只关闭一个tkinter窗口

时间:2016-12-01 14:42:55

标签: python button tkinter window

我可以让我的程序关闭整个程序,无论我还没有找到方法,这样当点击一个按钮时它只会关闭那个窗口而不是整个程序。

 from tkinter import *


class First(object):

    def __init__(self, master):
        self.master = master
        self.admin_btn = Button(self.master, text = "First", command = self.second)
        self.admin_btn.grid(row = 0, column = 0)

    def second(self):
        self.w = second(self.master)
        self.master.wait_window(self.w.master)


class second(object):

    def __init__(self, master):
        self.master = Toplevel(master)
        self.second = Button(self.master, text = "Second", command = self.third)
        self.second.grid(row= 0, column = 0)

    def third(self):
        self.w = third(self.master)
        self.master.wait_window(self.w.master)


class third(object):

    def __init__(self, master):
        self.master = Toplevel(master)
        self.second = Button(self.master, text = "Third")
        self.second.grid(row= 0, column = 0)
        ## The close button, not linked to any command
        self.close = Button(self.master, text = "Close")
        self.close.grid(row = 1, column = 0)


if __name__ == "__main__":
    root = Tk()
    first = First(root)
    root.mainloop()

0 个答案:

没有答案