Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python gui按钮(tkinter)函数在程序执行时运行,而不是onclick_Python_User Interface_Button_Tkinter - Fatal编程技术网

Python gui按钮(tkinter)函数在程序执行时运行,而不是onclick

Python gui按钮(tkinter)函数在程序执行时运行,而不是onclick,python,user-interface,button,tkinter,Python,User Interface,Button,Tkinter,我目前正在学习python/tkinter,我有两个按钮工作正常,但我的最后一个按钮被分配给一个函数,该函数应该在单击时运行,但它会在程序执行时运行,然后在单击按钮时不会运行。我已经看了几个其他的线程,无法找出为什么我的线程不能工作 非常感谢 def onclickSelectSheet(): test() buttonSelectSheet = Button(topFrame, text="Select an information sheet", command=onclickS

我目前正在学习python/tkinter,我有两个按钮工作正常,但我的最后一个按钮被分配给一个函数,该函数应该在单击时运行,但它会在程序执行时运行,然后在单击按钮时不会运行。我已经看了几个其他的线程,无法找出为什么我的线程不能工作

非常感谢

def onclickSelectSheet(): 
    test()

buttonSelectSheet = Button(topFrame, text="Select an information sheet", command=onclickSelectSheet(), bg = '#CDCDCD')
buttonSelectSheet.place(relx=0.2, rely=0.1, relwidth=0.6, relheight=0.4) 

要在单击时执行按钮命令,您需要设置
命令
选项,如下所示:

Button(..., command=lambda: onclickSelectSheet(),...) # with parenthesis


使用括号
()
而不使用
lambda
在定义
按钮
小部件后立即执行该功能

非常感谢,简短而甜蜜的解释,完全有意义!
Button(..., command=onclickSelectSheet,...) # without parenthesis