2
當我多次按下「Enter」按鈕時,文本字段將繼續顯示,但我需要它,這樣一旦我輸入了我的名字並按下按鈕,該按鈕就會停用。我該怎麼做呢?如何驗證tkinter中的按鈕,以便該函數只被調用一次?
class Enter_Name_Window(tk.Toplevel):
'''A simple instruction window'''
def __init__(self, parent):
tk.Toplevel.__init__(self, parent)
self.text = tk.Text(self, width=40, height=2)
self.text.pack(side="top", fill="both", expand=True)
self.text.insert("end", "Please enter your name and class. ")
enter_name = Entry(self)
enter_name.pack()
enter_name.focus_set()
def callback():
self.display_name = tk.Text(self, width=40, height=2)
self.display_name.pack(side="top", fill="both", expand=True)
self.display_name.insert("end", "Now please enter your tutor group.")
tutor = Entry(self)
tutor.pack()
tutor.focus_set()
Enter_0_2 = Button(self, text="Enter", width=10, command=callback2)
Enter_0_2.pack()
def callback2():
self.display_name = tk.Text(self, width=40, height=2)
self.display_name.pack(side="top", fill="both", expand=True)
self.display_name.insert("end", "Let's begin! Exit back to main screen.")
Enter_0 = Button(self, text="Enter", width=10, command=callback)
Enter_0.pack()
「活性」應當被只有當鼠標指針懸停按鈕,否則使用「正常」是正確的狀態。 –
@BryanOakley感謝您的糾正,我已經更新了答案。 – Fiver