[英]How can I reprogram the 'Ok' button in the Tkinter Messagebox module
我正在使用我的第一個Python GUI,在單擊消息的“確定”按鈕后,我想從代碼中關閉所有以前的窗口
messagebox.showinfo('Access Granted', 'Your data has been retrieved.')
tkinter對話框返回一個表示用戶單擊的字符串,因此只需保存該值並隨后進行檢查即可。 但是,由於showinfo
僅為用戶提供一個選項,因此它將始終返回"ok"
,因此無需檢查該值。 對話框顯示后,只需調用您的函數即可:
def some_function():
messagebox.showinfo('Access Granted', 'Your data has been retrieved.')
root.destroy()
...
button = tk.Button(root, text="Quit", command=some_function)
因此,假設您的窗口被稱為根目錄,則需要先定義一個“銷毀”窗口的函數
def closeWindow():
root.destroy()
然后,您想要將該命令添加到按鈕中-
btn = tkinter.Button(text="Click Me!" command=closeWindow)
如果您還有其他錯誤,請通知我!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.