Python Forum

Full Version: help with game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
No, I didn't changed any thing

And this exact problem is in all the codes

They all work perfectly, but just up+left not working. Haha

Really weird :)
Try with all keys binding to the canvas not root window.
Still the same problem
Try changes arrows keys wasd.
# moving ship
    if Game.keys_press.get('a', False):
        Game.canvas.move(Game.ship, -Game.ship_speed, 0)
    if Game.keys_press.get('d', False):
        Game.canvas.move(Game.ship, Game.ship_speed, 0)
    if Game.keys_press.get('w', False):
        Game.canvas.move(Game.ship, 0, -Game.ship_speed)
    if Game.keys_press.get('s', False):
        Game.canvas.move(Game.ship, 0, Game.ship_speed)
    if Game.keys_press.get('space', False):
        if pauser_elaspe(Game.shoot_pauser, Game.ticks):
            shoot()
Now it works correctly
Sounds like a keyboard error.
Can you tell me about where can I find a good tutorial about tkinter and bindings with detail

Hhhhhh

I don't understand.

Maybe it about the version of python!!!

I use 3.6

Even with 3.5 and 2.7.12


Has the same problem
i use python 3.6. Arrows keys and wasd keys should work the same. So sound like need test with another keyboard. To see if you get same results.

I use this PDF .
Here a small key press and release program example
import tkinter as tk

class App:
    pass
    
def event_press(event):
    if App.texts.get(event.keysym, False) is False:
        App.texts[event.keysym] = tk.Label(App.frame, text='Key Press ' + event.keysym)
        App.texts[event.keysym].pack()
    else:
        App.texts[event.keysym]['text'] = 'Key Press ' + event.keysym

    
def event_release(event):
    # numlock
    if event.keysym.startswith('KP') and event.char != '':
        key = 'KP_' + event.char
    else:
        key = event.keysym
        
    if App.texts.get(key, False):
        App.texts[key]['text'] = 'Key Release ' + key
    
def main():
    App.SCREEN_SIZE = {'w':600, 'h':400}
    App.root = tk.Tk()
    App.frame = tk.Frame(App.root, width=App.SCREEN_SIZE['w'], height=App.SCREEN_SIZE['h'])
    App.frame.pack()
    App.texts = {}
    App.frame.bind_all('<KeyPress>', event_press)
    App.frame.bind_all('<KeyRelease>', event_release)
    App.root.mainloop()
    
if __name__ == '__main__':
    main()    
    
Thank you for the ebook


Iam using laptop "azerty" keyboard, I don't have USB keyboard
Pages: 1 2 3 4 5