forked from flatplanet/Intro-To-TKinter-Youtube-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas_img.py
56 lines (35 loc) · 761 Bytes
/
canvas_img.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
from tkinter import *
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)
# Add Image To Canvas
img = PhotoImage(file="c:/gui/images/me.png")
my_image = my_canvas.create_image(260,125, anchor=NW, image=img)
def left(event):
x = -10
y = 0
my_canvas.move(my_image, x, y)
def right(event):
x = 10
y = 0
my_canvas.move(my_image, x, y)
def up(event):
x = 0
y = -10
my_canvas.move(my_image, x, y)
def down(event):
x = 0
y = 10
my_canvas.move(my_image, x, y)
root.bind("<Left>", left)
root.bind("<Right>", right)
root.bind("<Up>", up)
root.bind("<Down>", down)
root.mainloop()