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
  Button to stop while loop from another script Absolutewind 5 884 Sep-25-2023, 11:20 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 872 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Tkinter button images not showing up lunacy90 7 1,569 Aug-31-2023, 06:39 PM
Last Post: deanhystad
Bug tkinter.TclError: bad window path name "!button" V1ber 2 777 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Start print a text after open an async task via button Nietzsche 0 702 May-15-2023, 06:52 AM
Last Post: Nietzsche
  Confirm / Cancel button in Python & Flask ladak 0 786 Mar-18-2023, 11:26 AM
Last Post: ladak
  Checkbox itens with a button to run action Woogmoog 3 945 Dec-19-2022, 11:54 AM
Last Post: Woogmoog
  How to break out of a for loop on button press? philipbergwerf 6 1,740 Oct-06-2022, 03:12 PM
Last Post: philipbergwerf
  How to create a menu button? Frankduc 30 5,233 Mar-09-2022, 10:37 PM
Last Post: deanhystad
  user interface Button not working Frankduc 4 1,448 Feb-16-2022, 02:52 PM
Last Post: Frankduc

Forum Jump:

User Panel Messages

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