0

i'm currently learning python/tkinter and I have two buttons working correctly but my final button is assigned to a function, which is supposed to run on click but it instead runs when the program is executed and then will not run when the button is clicked. I have looked at a couple of other threads and cannot work out why mine wont work.

Thanks a lot

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) 

1 Answers1

1

To execute a Button-command on click, you need to set the command option as follows:

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

OR

Button(..., command=onclickSelectSheet,...) # without parenthesis

Using parenthesis () without lambda executes the function as soon as the Button widget is defined

FrainBr33z3
  • 1,085
  • 1
  • 6
  • 12