forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationDemo.py
33 lines (27 loc) · 1.1 KB
/
AnimationDemo.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
from tkinter import * # Import tkinter
class AnimationDemo:
def __init__(self):
window = Tk() # Create a window
window.title("Animation Demo") # Set a title
width = 250 # Width of the canvas
canvas = Canvas(window, bg = "white",
width = 250, height = 50)
canvas.pack()
x = 0 # Starting x position
canvas.create_text(x, 30,
text = "Message moving?", tags = "text")
dx = 3
while True:
canvas.move("text", dx, 0) # Move text dx unit
canvas.after(100) # Sleep for 100 milliseconds
canvas.update() # Update canvas
if x < width:
x += dx # Get the current position for string
else:
x = 0 # Reset string position to the beginning
canvas.delete("text")
# Redraw text at the beginning
canvas.create_text(x, 30, text = "Message moving?",
tags = "text")
window.mainloop() # Create an event loop
AnimationDemo() # Create GUI