python Tkinter()如何隐藏用户界面
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python Tkinter()如何隐藏用户界面,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2404字,纯文字阅读大概需要4分钟。
内容图文
![python Tkinter()如何隐藏用户界面](/upload/InfoBanner/zyjiaocheng/659/6dc05f76af6646fbba8ac0bab4240185.jpg)
嗨,我正在使用Tkinter()在python中开发单个登录,我只希望当用户正确登录时,登录UI会被隐藏,而内容UI会显示…所以我一直认为ui可以被隐藏否则可见性将被隐藏?
例如我有这段代码…
def httpGETCheck(username, password):
....
# assumed that the user is correct
if registeredUser:
# how can I hide or set visible is false to all the UI in the showLogin() Module
# and how can I show the showContent() UI or replaced the showContent() UI from showLogin() UI
class ContentUI():
def showContent(self, frame):
button1 = Button(frame, text="+", width=15, command=counterPlus)
button1.grid()
def showLogin(self, frame):
self.contentUI = ContentUI()
L1 = Label(frame, text="User Name")
L1.pack( side = LEFT)
L1.grid()
E1 = Entry(frame, bd =5)
E1.pack(side = RIGHT)
E1.grid()
L2 = Label(frame, text="Password")
L2.pack( side = LEFT)
L2.grid()
E2 = Entry(frame, bd =5, show="*")
E2.pack(side = RIGHT)
E2.grid()
submit = Button(frame, text="Login", width=15, command=lambda: httpGETCheck(E1.get(), E2.get()))
submit.grid()
class UIDisplay():
def play(self):
root = Tk()
root.title(title)
root.geometry(dimension)
app = Frame(root)
contentUI = ContentUI()
contentUI.showLogin(app)
app.grid()
root.mainloop()
ad = UIDisplay()
ad.play()
解决方法:
这里是一种替代方法:定义框架中的每个“页面”.然后使用呼叫提起以将适当的框架升高到其他框架之上. (以下代码大量借鉴了Bryan Oakley的代码here.)
import tkinter as tk
class Page(tk.Frame):
def __init__(self, master, text, height, width, *args, **kwargs):
tk.Frame.__init__(self, *args, borderwidth=20, **kwargs)
self.height = height
self.width = width
button = tk.Button(self, text=text, font=('Comic Sans MS', 20),
command=lambda: self.callback())
button.pack(side="top", fill="both", expand=True)
def onlift(self):
root.geometry('{}x{}'.format(self.width, self.height))
self.lift()
class App(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
p1 = Page(self, 'Login 1', height=200, width=300)
p2 = Page(self, 'Next page is 2', height=400, width=300)
p3 = Page(self, 'We love number 3', height=400, width=600)
p1.callback = p2.onlift
p2.callback = p3.onlift
p3.callback = p1.onlift
p1.place(x=0, y=0, relwidth=1, relheight=1)
p2.place(x=0, y=0, relwidth=1, relheight=1)
p3.place(x=0, y=0, relwidth=1, relheight=1)
p1.onlift()
root = tk.Tk()
app = App(root)
root.mainloop()
在上面,我仅定义了一种框架,称为Page.对于您的情况,您需要一个登录框架,然后是一个后续框架:
p1 = Login(self, ...)
p2 = Registered(self, ...)
内容总结
以上是互联网集市为您收集整理的python Tkinter()如何隐藏用户界面全部内容,希望文章能够帮你解决python Tkinter()如何隐藏用户界面所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。