按下按钮时如何关闭tkinter窗口?

时间:2014-03-13 05:49:27

标签: python tkinter

def _error_message(self, message: str):
    self._error_window = tkinter.Toplevel()
    title = tkinter.Label(master = self._error_window,
        text = message, font = DEFAULT)
    title.grid(row = 0, padx = 12, pady = 12, sticky = tkinter.EW)

    ok_error_button = tkinter.Button(master=self._error_window, text='OK',
        font= DEFAULT, command = self._error_window.destroy())
    ok_error_button.grid(row = 1, padx = 10, pady = 10)

    self._error_window.grab_set()

我想按下" ok"窗口上的按钮关闭窗口我该怎么做?

2 个答案:

答案 0 :(得分:1)

将按钮的命令名称更改为self.destroy 在初始化按钮之前添加它:

def destroy(self)
    self._error_window.destroy()

祝你好运!

答案 1 :(得分:0)

def quit(self):
    self._error_window.destroy()