Tkinter Details

I was working on a very simple game. When you see two shapes of the same color, you need to "snap" them. I was following a tutorial from a book to write this program. They decided to use the tkinter module for the GUI. You would think that pygame is the right tool for the job. But I guess there are many ways to code a game.

The user presses a key (such as the letter q) to to perform a snap when they see matching colors. I was trying to trap this key press event like this:

    Canvas.bind('q',my_handler_fxn)

However, my function was never getting called when I pressed the key. I was banging my head against the wall for a little while. Then I identified that you need to tell tkinter to send those key press events to the Canvas object with this simple call:

    Canvas.focus_set()

With that small details taken care of, I was off to the races playing my snap game.



Popular posts from this blog

HTML Web Page Builder

Memories of Logo

Mission Accepted