Okay, I'm trying to make a python game (not with pygame), I want it to use the arrow keys. But the thing is, I don't know how to get it to respond to the arrow keys. So here's what I want to do.
If the user presses the up arrow key set the variable 'direction' to up, if the press the down arrow key set direction to 'down' etc. Would this be possible? If so, how? The only thing I know is that you need to use KeyboardInterupt or something like that.
The Tkinter code has been working great for me- However, I was wondering if there was a way to pass additional variables into the key function. I also haven't been able to get it to work without showing the tk window.
It will constantly set the variable 'key', to whatever arrow key you press. If you wish to stop the background code at any time just do 'Break_KeyCheck = True' if you want to start it again do 'Break_KeyCheck = False'. I hope that helps. This also solves the issue, if you click on the screen it stops working. This is more simpler, so you should be able to use this to solve your issue.
Last edited by AutoPython; Dec 27th, 2009 at 3:38 pm.
The code does not work on my Mac. If I comment out the withdrawing of the root window then it works fine as long as I make the root window focused. Tested for Python 3.2.2 and Python 2.7.2.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.