[Solved] Tkinter Function attached to Button executed immediately [duplicate]


The solution is to pass the function as a lambda:

from Tkinter import *

root =Tk()

def callback(parameter):
    print parameter

button = Button(root, text="Button", command=lambda: callback(1))
button.pack()

root.mainloop()

Also, as @nbro already correctly pointed out, the button attribute is command, not function.

1

solved Tkinter Function attached to Button executed immediately [duplicate]