【发布时间】:2019-01-29 12:25:12
【问题描述】:
我刚开始使用我的第一个 Python 程序,遇到了一个非常奇怪的函数回调问题。这是符合我期望的代码:
from tkinter import *
def say_hello():
print('hello')
root = Tk()
Button(root, text='say hello', command=say_hello).pack()
root.mainloop()
现在,如果我在函数名称中添加括号
Button(root, text='say hello', command=say_hello()).pack()
'hello' 只会在程序启动时打印一次,但在单击按钮时不会再有任何反应。为什么?
谢谢!
【问题讨论】: