Reputation:
I am trying to make a button that increases money or something, but i am just trying to test it out in another project
This is my code for the button
global counterCheck
counterCheck = 0
def checkClick():
global counterCheck
counterCheck += 1
textClick.config(text=counterCheck)
bttt = Button(root, width=1720, height=600, text="Click Here", command=checkClick)
bttt.bind("<space>", checkClick())
bttt.pack()
Upvotes: 0
Views: 844
Reputation: 82949
There are actually multiple problems with your code. The first one is a common problem, but there is more:
None
, to the event; instead, you have to bind the function itselfButton.command
, when a function is called via bind
, it will get an parameter, the event that triggered itI actually did not manage to unbind
the "press on space-key" action from the Button, so one workaround (besides never giving the button the focus) would be to use a different key, e.g. Return
, and bind that to root
or use bind_all
so it is bound to all widgets.
def checkClick(*unused): # allow optional unused parameters
...
root.bind("<Return>", checkClick) # function itself, no (), root, and Return
After this, there are three ways to trigger the button:
command
Return
key, calling the key event bindingUpvotes: 2