我希望能够打开另一个窗口并破坏当前的登录窗口,只有在登录详细信息正确后。
我已将当前登录窗口设置为顶级并撤消了根窗口,我猜我现在需要销毁Toplevel并调用root,但是这样做的确切方法我不确定。任何帮助,将不胜感激。
from Tkinter import *
import tkMessageBox
import time
#Login details
username = ("admin")
password = ("")
#Login attempt
def try_login():
print("Trying to login...")
if username_guess.get() == username:
tkMessageBox.showinfo("COMPLETE", "You Have Now Logged In.", icon="info")
else:
tkMessageBox.showinfo("-- ERROR --", "Please enter valid infomation!", icon="warning")
#Gui Things
root = Tk()
top = Toplevel()
top.configure(bg='lightgrey')
top.resizable(width=FALSE, height=FALSE)
top.title("Log-In")
top.geometry("200x160")
# change window icon
top.wm_iconbitmap(r'C:\Python27\py.ico')
top.wm_title('APP')
#Time and Date
time1 = ''
clock = Label(top, font=('times', 10, 'bold'), bg='lightgrey')
clock.pack(side="bottom", fill='both', expand=False, ipadx=0, ipady=0)
def tick():
global time1
time2 = time.strftime("%d-%m-%Y %H:%M")
if time2 != time1:
time1 = time2
clock.config(text=time2)
clock.after(200, tick)
tick()
#Creating the username & password entry boxes
username_text = Label(top, text="Username:", bg='lightgrey')
username_guess = Entry(top)
password_text = Label(top, text="Password:", bg='lightgrey')
password_guess = Entry(top, show="*")
#attempt to login button
attempt_quit = Button(top, text="Quit", command=top.destroy).pack(side="bottom", fill='both', expand=False, padx=0, pady=0)
attempt_login = Button(top, text="Login", command=try_login).pack(side="bottom", fill='both', expand=False, padx=0, pady=0)
username_text.pack()
username_guess.pack()
password_text.pack()
password_guess.pack()
#Hides the root window
root.withdraw()
#Top Starter
top.mainloop()
答案 0 :(得分:0)
if username_guess.get() == username: tkMessageBox.showinfo("COMPLETE", "You Have Now Logged In.", icon="info")
在此行之后,您可以调用root.deiconify()
来显示根窗口,并top.destroy()
来杀死登录窗口。