-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove_image.py
More file actions
30 lines (21 loc) · 740 Bytes
/
move_image.py
File metadata and controls
30 lines (21 loc) · 740 Bytes
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
from tkinter import *
def move_up(event):
label.place(x=label.winfo_x(),y=label.winfo_y()-10)
def move_down(event):
label.place(x=label.winfo_x(),y=label.winfo_y()+10)
def move_left(event):
label.place(x=label.winfo_x()-10,y=label.winfo_y())
def move_right(event):
label.place(x=label.winfo_x()+10,y=label.winfo_y())
window = Tk()
window.title('A moving Images case')
window.geometry('500x500')
myImage = PhotoImage(file='img/smile.png')
label = Label(window,image=myImage)
label.place(x=250,y=250)
window.bind('<w>',move_up)
window.bind('<s>',move_down)
window.bind('<a>',move_left)
window.bind('<d>',move_right)
label2 = Label(text='Press w,a,s or d to move the smile',font=('Arial',20)).pack()
window.mainloop()