【问题标题】:tkinter, message box close program on click "ok" [duplicate]tkinter,单击“确定”时消息框关闭程序[重复]
【发布时间】:2023-04-07 07:31:01
【问题描述】:

一旦用户在消息框中点击OK,我如何关闭整个程序?

这是包含按钮和命令的脚本部分:

class Application(tk.Tk):
    def create_options(self):

        tk.Button(self,
                  text = "Begin search", command=self.pop_up1
                  ).place(x=465, y=285)

    def pop_up1(self):
        """shows submitted box"""
        tkMessageBox.showinfo(title="Finished", message="Query Submitted")

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    这取决于你退出整个程序的意思,你可以使用关闭窗口 self.root.destroy() 但是根据您的实现,关闭窗口可能不会结束您的程序,但通常这是您关闭 tkinter 应用程序的方式。只需将其添加到按钮事件的末尾即可。

    【讨论】:

    • 谢谢!我使用了 self.destroy() 并且成功了。
    • 不客气,祝你的项目好运:)
    • @TheHoff 记得通过单击左侧的复选标记将此答案标记为已接受。
    • @WayneWerner 知道了!
    猜你喜欢
    • 2013-07-08
    • 1970-01-01
    • 2014-08-23
    • 2021-03-16
    • 2018-10-09
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多