Advertisement
here2share

# Tk_arrowkeys.py

Sep 6th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # Tk_arrowkeys.py
  2. from Tkinter import *
  3. tk = Tk()
  4. canvas = Canvas(tk, width=400, height=400)
  5. canvas.pack()
  6.  
  7.  
  8. #Green circle creation
  9. target = canvas.create_oval(10, 10, 60, 60, fill='green')
  10. canvas.itemconfig(target, outline='black')
  11.  
  12. #Moving for green circle
  13. def mv(event):
  14.     if event.keysym == 'Up':
  15.         canvas.move(1, 0, -5)
  16.     elif event.keysym == 'Down':
  17.         canvas.move(1, 0, 5)
  18.     elif event.keysym == 'Left':
  19.         canvas.move(1, -5, 0)
  20.     else:
  21.         canvas.move(1, 5, 0)
  22.  
  23. #Making keys do something for green circle
  24. canvas.bind_all('<KeyPress-Up>', mv)
  25. canvas.bind_all('<KeyPress-Down>', mv)
  26. canvas.bind_all('<KeyPress-Left>', mv)
  27. canvas.bind_all('<KeyPress-Right>', mv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement