V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
sudoy
V2EX  ›  Python

tkinter 用 withdraw() 隐藏主界面作为登录原理是否是一个好办法?

  •  
  •   sudoy · 2020-06-04 09:49:25 +08:00 · 3428 次点击
    这是一个创建于 1426 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用 python tkinter 写了个 Windows 桌面程序, 想做个登录界面,用户登录通过以后再跳转到主界面。找了很久终于找到一个能达到目的的方法,但是不知道这个方法是否存在安全隐患,也就是说用户能轻松跳过验证直接显示主界面。顺便说一下这个程序会编译成 exe 。以下是原理:

    import tkinter as tk
    
    root = tk.Tk()
    root.geometry('500x300')
    
    #In order to hide main window
    root.withdraw()
    
    tk.Label(root, text="Main Window").pack()
    
    aWindow = tk.Toplevel(root)
    aWindow.geometry('200x100')
    
    def change_window():
        #remove the other window entirely
        aWindow.destroy()
    
        #make root visible again
        root.iconify()
        root.deiconify()
    
    username = tk.StringVar()
    tk.Entry(aWindow,  textvariable=username).pack()
    tk.Button(aWindow, text="Login", command=change_window).pack()
    
    root.mainloop()
    

    欢迎大佬们指点,多谢!

    6 条回复    2020-10-15 10:09:42 +08:00
    no1xsyzy
        1
    no1xsyzy  
       2020-06-04 09:57:09 +08:00
    Python 一般没有真 exe
    chengxiao
        2
    chengxiao  
       2020-06-04 10:29:01 +08:00
    真的要用 Python 写 GUI 的话,还是去看下 PyQT 吧
    tk 折腾过一段时间发现实在是太难用了
    sudoy
        3
    sudoy  
    OP
       2020-06-04 10:32:22 +08:00
    @chengxiao 已经决定用 kivy 了,不过目前用 tk 写的已经再运行了暂时不想改。tk 有很多地方没法实现
    XIVN1987
        4
    XIVN1987  
       2020-06-04 15:49:59 +08:00
    Tk 的界面这么丑,我不明白 Python 为啥一定要带着它

    真觉得 GUI 必须,,换个好看点儿的不行吗??哪怕功能简陋些也许啊
    panzhangwang
        5
    panzhangwang  
       2020-06-05 09:02:22 +08:00
    pysimplegui 推荐看下, 自动 Port 到 Tk, Qt 呀。 最近刚用它做了一个项目

    https://github.com/cailaixiu/cailaixiu
    ungrown
        6
    ungrown  
       2020-10-15 10:09:42 +08:00
    @XIVN1987 #4 主要是体积贼小
    至于难用这方面,配合一些纯 python 的开源库,可以做到极少代码生成 UI (非复杂类型)
    最终用极小的体积实现了不小的功能
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1467 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:46 · PVG 00:46 · LAX 09:46 · JFK 12:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.