繁体   English   中英

如何在Tkinter消息框模块中重新编程“确定”按钮

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM