import tkinter as tk
root = tk.Tk()
root.geometry("1800x1350")
canvas = tk.Canvas(root, width=400, height=50)
canvas.pack()
text = canvas.create_text(0, 20, anchor="w", text="This is a scrolling marquee!", font=("Arial", 18))
def scroll_marquee():
canvas.move(text, 1, 0)
if canvas.coords(text)[0] > 400:
canvas.coords(text, -100, 20)
# Call this function again after a short pause
root.after(10, scroll_marquee)
# Start the scrolling loop
scroll_marquee()#宽度为400像素的Canvas,然后在其中创建一个水平滚动的文本框。scroll_marquee()函数会持续调用,并且每次将文本框向右移动1个像素。如果文本框的坐标在Canvas的右侧,则将其重新定位到Canvas的左侧,从而实现无限循环的跑马灯效果。
root.mainloop()
09-10
06-21
450
10-06
1392