forked from flatplanet/Intro-To-TKinter-Youtube-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrows2.py
67 lines (45 loc) · 1003 Bytes
/
arrows2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from tkinter import *
import tkinter.ttk as ttk
root = Tk()
root.title('Codemy.com')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("800x600")
w = 600
h = 400
x = w/2
y = h/2
my_canvas = Canvas(root, width=w, heigh=h, bg="white")
my_canvas.pack(pady=20)
#my_circle = my_canvas.create_oval(x, y, x+20, y+20 )
img = PhotoImage(file="images/me.png")
me = my_canvas.create_image(275,100, anchor=NW, image=img)
def left(event):
x = -10
y = 0
my_canvas.move(me, x, y)
def right(event):
x = 10
y = 0
my_canvas.move(me, x, y)
def up(event):
x = 0
y = -10
my_canvas.move(me, x, y)
def down(event):
x = 0
y = 10
my_canvas.move(me, x, y)
def pressing(event):
x = 0
y = 0
if event.char == "a": x = -10
if event.char == "d": x = 10
if event.char == "r": y = -10
if event.char == "x": y = 10
my_canvas.move(my_circle, x, y)
root.bind("<Key>", pressing)
root.bind("<Left>", left)
root.bind("<Right>", right)
root.bind("<Up>", up)
root.bind("<Down>", down)
root.mainloop()