-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimation.py
35 lines (26 loc) · 886 Bytes
/
Animation.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
from tkinter import *
import time
WIDTH=500
HEIGHT=500
xVelocity=1
yVelocity=1
window=Tk()
canvas=Canvas(window,width=WIDTH,height=HEIGHT)
canvas.pack()
background=PhotoImage(file="C:\\Users\\Sahib\\Desktop\\Coding\\Test\\index1.png")
my_image=canvas.create_image(0,0,image=background,anchor=NW)
photo=PhotoImage(file="C:\\Users\\Sahib\\Desktop\\Coding\\Test\\index.png")
my_image=canvas.create_image(0,0,image=photo,anchor=NW)
image_width=photo.width()
image_height=photo.height()
while True:
coordinates=canvas.coords(my_image)
print(coordinates)
if(coordinates[0]>=(WIDTH-image_width) or coordinates[0]<0): #x ucundur
xVelocity=-xVelocity
if(coordinates[1]>=(HEIGHT-image_height) or coordinates[1]<0): #y ucundur
yVelocity=-yVelocity
canvas.move(my_image,xVelocity,yVelocity)
window.update()
time.sleep(0.01)
window.mainloop()