Python Forum

Full Version: tkinter button executes button before being clicked
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a button and when I start the program it does just fine because the button is in a function, but when then function is executed to create the buttons, it automatically executes the function the button is supposed to execute upon being clicked on. i had this problem before and someone told me to take the parenthesis off. In that case it worked, but it won't in this case as I need to send info to the function the button is executing. Thx in Advance

This is the function -
def Shoton():
            ShotonButton = Button(tk, text="", command=Char.CharSel(1), bg='red')
            ShotonButton.config(image=ShotonImage, width=130, height=200 )
            ShotonButton.place(relx=.1, rely=.1)
            ShotonLabel = canvas.create_text(145, 310, text='Shoton', fill='red', font=('Times', 30))
Use partial
i think this is correct usage, unable to test with code shown.
from functools import partial
#
#
#
ShotonButton = Button(tk, text="", command=partial(Char.CharSel, 1), bg='red')