-1

I want to run my code when Button_1 is pressed. So something like :

def buttonPress(self, event):
    (Not sure what to put here)

def playGamesWith(self, aiPlayer):
 if buttonPress == True:
    ...

Would this be the right approach? Create a function that checks for the event then returns true when it is pressed? If so, how would I do that?

2
  • 2
    I think what you are trying to find, this link contains the same. stackoverflow.com/questions/6874525/… Commented Nov 25, 2019 at 20:33
  • This is covered in proably every single tkinter tutorial and documentation site out there. Why do you need our help? Commented Nov 25, 2019 at 20:39

1 Answer 1

0

If your window is called root, use

root.bind("<Button-1>", handler)

where handler is a function that should be executed when button 1 is pressed.

Sign up to request clarification or add additional context in comments.

2 Comments

Where would this line be located? In my main() ?
@RonnyValtonen Where you create the root window (Tk()).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.