当我制作很多gui时,我想用一个按钮关闭所有gui。谁知道怎么做?

时间:2017-08-01 04:29:52

标签: python-3.x tkinter

当我按下make gui按钮很多次我会得到很多gui但是当我按下关闭gui按钮时它会关闭一个gui。为什么呢?

 from tkinter import *

   showw = Tk()
   showw.withdraw()

   def Quit(event):

      showw.withdraw()

   def show(event):
        global showw
        global cnt
        showxyUI = Tk()
        showxyUI.title("X and Y ")
        showxyUI.geometry("200x100")
        showw = showxyUI
  programInterface = Tk()
  programInterface.title("GUI")

  myButton = Button(programInterface,text="make gui",bg="red",fg="white",width= 20,height=3)
  myButton.bind('<Button-1>',show)
  myButton.pack()
  button = Button(programInterface,text="close gui",bg="red",fg="white",width= 20,height=3)
  button.bind('<Button-1>',Quit)
  button.pack()
  programInterface.mainloop()

1 个答案:

答案 0 :(得分:-1)

建议你写一个清晰的代码! (选择合适的名称,空格等) 这个惯例,提高了可读性,使您的代码易于调试。

from tkinter import *

popup_list = []


def quit_all():
    popup_list.pop().destroy()


def create_popup():
    popup = Tk()
    popup.title("Pop-Up window")
    popup.geometry("200x100")
    popup_list.append(popup)

if __name__ == '__main__':
    main = Tk()
    main.title("GUI")

    make_button = Button(main, text="make popup", bg="red", fg="white", width=20, height=3, command=create_popup)
    make_button.pack()

    quit_button = Button(main, text="close popup", bg="red", fg="white", width=20, height=3, command=quit_all)
    quit_button.pack()

    main.mainloop()