概述
下面的代码可用于获得所需的效果,并对其进行了注释,以显示每一步所发生的情况:from tkinter import * #Imports Tkinter
import sys #Imports sys, used to end the program later
root=Tk() #Declares root as the tkinter main window
top = Toplevel() #Creates the toplevel window
entry1 = Entry(top) #Username entry
entry2 = Entry(top) #Password entry
button1 = Button(top, text="Login", command=lambda:command1()) #Login button
button2 = Button(top, text="Cancel", command=lambda:command2()) #Cancel button
label1 = Label(root, text="This is your main window and you can input anything you want here")
def command1():
if entry1.get() == "user" and entry2.get() == "password": #Checks whether username and password are correct
root.deiconify() #Unhides the root window
top.destroy() #Removes the toplevel window
def command2():
top.destroy() #Removes the toplevel window
root.destroy() #Removes the hidden root window
sys.exit() #Ends the script
entry1.pack() #These pack the elements, this includes the items for the main window
entry2.pack()
button1.pack()
button2.pack()
label1.pack()
root.withdraw() #This hides the main window, it's still present it just can't be seen or interacted with
root.mainloop() #Starts the event loop for the main window
这将使用Toplevel小部件来创建一个窗口,该窗口询问用户的详细信息,然后将他们引导到主窗口,您可以根据需要进行设置。在
您还可以使用示例中使用的弹出消息,如果需要,还可以更改Toplevel小部件的大小。在
但请注意,这不是一种特别安全的管理密码和登录的方式。因此,我建议您在编程中查找处理敏感信息的适当礼仪。在
最后
以上就是矮小吐司为你收集整理的python3.6 messagebox_如何在Tkinter(Python3.6)中成功登录后显示主窗口的全部内容,希望文章能够帮你解决python3.6 messagebox_如何在Tkinter(Python3.6)中成功登录后显示主窗口所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复