我正在使用Python 3.4.2。请帮助我理解使用classname.method(self)和self.method后获得的输出值之间的差异。当我运行程序时,输出显示在IDLE上,然后在classname.method(self)时单击第一个按钮。然而,如果我使用command = self.method,它将等待我单击按钮然后打印输出。为什么会这样?请任何人解释一下。
from tkinter import *
class Application(Frame):
def __init__(self , master):
Frame.__init__(self,master)
self.grid()
def create_widgets(self):
self.button = Button(self, text = '1st Button')
self.button.grid()
self.button["command"] = Application.say_hello(self)
self.but1=Button(self)
self.but1.grid()
self.but1.configure(text = '2nd Button' ,command = self.say_i_quit)
def say_hello(self):
print("Hi.. I am the 1st button..")
def say_i_quit(self):
print("Hey... I QUIT...")
root.destroy()
root = Tk()
root.title("File Name")
root.geometry('500x500')
app = Application(root)
app.create_widgets()
root.destroy
root.mainloop()