-1

I created a button "button" and I want to call a function "function" when I press on this button. When I run the program, the function is called and then the button appears. If I press it once again, the function is not called. So how to disable calling the function without pressing the button and how to enable calling the function at each press on the butotn?


from tkinter import *

def function():
   what this function does

root = Tk()
button = Button(root,text="Call function", command=function())
button.pack()
root.mainloop()

2 Answers2

1

You need to pass the function (don't call it):

button = Button(root,text="Call function", command=function)
Jakub Szlaur
  • 1,852
  • 10
  • 39
1

I think you have to remove the brackets from the function, because you just want to give the function as a parameter to your button and you do not want to call the function instead.

So it will look like: button = Button(root,text="Call function", command=function)

Graf-J
  • 81
  • 5