Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_arrowkeys.py
- from Tkinter import *
- tk = Tk()
- canvas = Canvas(tk, width=400, height=400)
- canvas.pack()
- #Green circle creation
- target = canvas.create_oval(10, 10, 60, 60, fill='green')
- canvas.itemconfig(target, outline='black')
- #Moving for green circle
- def mv(event):
- if event.keysym == 'Up':
- canvas.move(1, 0, -5)
- elif event.keysym == 'Down':
- canvas.move(1, 0, 5)
- elif event.keysym == 'Left':
- canvas.move(1, -5, 0)
- else:
- canvas.move(1, 5, 0)
- #Making keys do something for green circle
- canvas.bind_all('<KeyPress-Up>', mv)
- canvas.bind_all('<KeyPress-Down>', mv)
- canvas.bind_all('<KeyPress-Left>', mv)
- canvas.bind_all('<KeyPress-Right>', mv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement