如何将master = Tk()
到__init__
tkinter.Frame的子类的
产生两个窗口( app
和app2
)当只有app.mainloop()
被调用?
from tkinter import Frame,Button,Tk
class Application(Frame):
def say_hi(self):
print('Hello world?!')
def close(self):
self.master.destroy()
def createWidgets(self):
self.quit_b = Button(self, width=12, text='Quit', bg='tan',
command=self.close)
self.quit_b.grid(row=0, column=0, padx=8, pady=8)
self.hello_b = Button(self, width=12, text='Hello',
command=self.say_hi)
self.hello_b.grid(row=0, column=1, padx=8, pady=8)
def __init__(self):
master = Tk() # <------------------------ ! see here !
Frame.__init__(self, master)
self.grid()
self.createWidgets()
app = Application()
app.master.title('Hello world!')
app2 = Application()
app2.master.title('Hello world! 2')
app.mainloop()