【发布时间】:2015-10-31 04:14:29
【问题描述】:
我试图在 if 语句中使用它来检查用户名是否等于接受的答案。我在我的 ent_username 上使用了 .get() 来尝试选择名称,但它不起作用。是不是它永远不会真正被输入,因为用户名我需要用按钮做更多的代码。请帮忙....
import tkinter
action = ""
#create new window
window = tkinter.Tk()
#name window
window.title("Basic window")
#window sized
window.geometry("250x200")
#creates label then uses ut
lbl = tkinter.Label(window, text="The game of a life time!", bg="#a1dbcd")
#pack label
lbl.pack()
#create username
lbl_username = tkinter.Label(window, text="Username", bg="#a1dbcd")
ent_username = tkinter.Entry(window)
#pack username
lbl_username.pack()
ent_username.pack()
#attempting to get the ent_username info to store
username = ent_username.get()
#configure window
window.configure(background="#a1dbcd")
#basic enter for password
lbl_password = tkinter.Label(window, text="Password", bg="#a1dbcd")
ent_password = tkinter.Entry(window)
#pack password
lbl_password.pack()
ent_password.pack()
#def to check if username is valid
def question():
if username == "louis":
print("you know")
else:
print("failed")
#will make the sign up button and will call question on click
btn = tkinter.Button(window, text="Sign up", command=lambda: question())
#pack buttons
btn.pack()
#draw window
window.mainloop()
【问题讨论】:
标签: python user-interface python-3.x tkinter