forked from flatplanet/Intro-To-TKinter-Youtube-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas_mouse.py
45 lines (29 loc) · 806 Bytes
/
canvas_mouse.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
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 move(e):
#e.x
#e.y
global img
img = PhotoImage(file="c:/gui/images/me.png")
my_image = my_canvas.create_image(e.x,e.y, image=img)
my_label.config(text="Coordinates x: " + str(e.x) + " y: " + str(e.y))
#root.bind("<Left>", left)
#root.bind("<Right>", right)
#root.bind("<Up>", up)
#root.bind("<Down>", down)
my_label = Label(root, text="")
my_label.pack(pady=20)
my_canvas.bind('<B1-Motion>', move)
root.mainloop()