import tkinter as tk
def start_scrolling():
"""Initiates the text scrolling animation."""
scroll_text()
def scroll_text():
"""Animates text from left to right."""
# Get current position
x, y = canvas.coords(text_id)
# If text goes beyond right edge, reset to left
if x > 400:
canvas.move(text_id, -450, 0)
else:
# Move text right by 5 pixels
canvas.move(text_id, 5, 0)
# Call this function again after 50ms for smooth animation
root.after(50, scroll_text)
root = tk.Tk()
root.title("Scrolling Text")
# Set up Canvas
canvas = tk.Canvas(root, width=400, height=100, bg='white')
canvas.pack()
# Create text object on canvas
text_id = canvas.create_text(-100, 50, text="Scrolling Text Example", font=
("Arial", 20), fill="blue")
# Start Button
start_btn = tk.Button(root, text="Start Scroll", command=start_scrolling)
start_btn.pack()
root.mainloop()
Tidak ada komentar:
Posting Komentar