Python Forum
tkinter button executes button before being clicked
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter button executes button before being clicked
#1
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))
Reply
#2
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')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Returning data on button click by buttons created by a loop bradells 3 406 Apr-23-2025, 03:01 PM
Last Post: Pedroski55
  I trying to automate the Variable Logon button using the python code but I couldn't surendrasamudrala 0 287 Mar-07-2025, 05:02 AM
Last Post: surendrasamudrala
  Placing image button on top of background image Sintek 1 505 Mar-02-2025, 05:36 PM
Last Post: Sintek
  gpiozero button turn off LED that is already on duckredbeard 3 865 Dec-11-2024, 06:23 PM
Last Post: duckredbeard
  Count Button Press chizzy101010 3 1,830 Jun-28-2024, 05:16 PM
Last Post: deanhystad
  Creating a deselect button dwayne091 2 1,155 May-18-2024, 08:41 AM
Last Post: dwayne091
  Button to stop while loop from another script Absolutewind 5 2,910 Sep-25-2023, 11:20 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 3,339 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Tkinter button images not showing up lunacy90 7 4,053 Aug-31-2023, 06:39 PM
Last Post: deanhystad
Bug tkinter.TclError: bad window path name "!button" V1ber 2 2,320 Aug-14-2023, 02:46 PM
Last Post: V1ber

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020