Quit Mainloop In Python
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 startin
Solution 1:
Call root.quit()
, not theMainFrame.quit
:
import Tkinter as tk
classCloseAfterFinishFrame1(tk.Frame): # Diz que herda os parametros de Framedef__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()
defCloseWindow(self):
# disable the button so pressing <SPACE> does not call CloseWindow again
self.button.config(state=tk.DISABLED)
self.forget()
CloseAfterFinishFrame2(self.master)
classCloseAfterFinishFrame2(tk.Frame): # Diz que herda os parametros de Framedef__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()
defCloseWindow(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
.
Post a Comment for "Quit Mainloop In Python"