quit mainloop in python

后端 未结 1 1665
长情又很酷
长情又很酷 2020-12-06 19:28

Although I am a kind of experimented programmer in other languages, I am very new in Python. I have been trying to do a very simple thing that is to quit the mainloop after

相关标签:
1条回答
  • 2020-12-06 20:22

    Call root.quit(), not theMainFrame.quit:

    import Tkinter as tk
    
    class CloseAfterFinishFrame1(tk.Frame):  # Diz que herda os parametros de Frame
        def __init__(self, master):
            self.master = master
            tk.Frame.__init__(self, master)  # Inicializa com os parametros acima!!
            tk.Label(self, text="Hi", font=("Arial", 16)).pack()
            self.button = tk.Button(self, text="I am ready",
                               command=self.CloseWindow, font=("Arial", 12))
            self.button.pack()
            self.pack()
    
        def CloseWindow(self):
            # disable the button so pressing <SPACE> does not call CloseWindow again
            self.button.config(state=tk.DISABLED)
            self.forget()
            CloseAfterFinishFrame2(self.master)
    
    class CloseAfterFinishFrame2(tk.Frame):  # Diz que herda os parametros de Frame
        def __init__(self, master):
            tk.Frame.__init__(self, master)  # Inicializa com os parametros acima!!
            tk.Label(self, text="Hey", font=("Arial", 16)).pack()
            button = tk.Button(self, text="the End",
                               command=self.CloseWindow, font=("Arial", 12))
            button.pack()
            self.pack()
    
        def CloseWindow(self):
            root.quit()
    
    root = tk.Tk()
    CloseAfterFinishFrame1(root)
    root.mainloop()
    

    Also, there is no need to make a class CloseEnd if all you want to do is call the function root.quit.

    0 讨论(0)
提交回复
热议问题