赞
踩
实例代码
- import tkinter as tk # 导入tkinter库,并重命名为tk
- mywindow = tk.Tk() # 创建一个窗体
- mywindow.title("滚动字幕效果") # 设置窗体的标题
-
- # 创建画布并布局
- mycanvas = tk.Canvas(mywindow,width=500,height=100,bg="black")
- mycanvas.pack()
- x = 0
- width = 500
- dx = 5
-
- mycanvas.create_text(x,50,text="你好,Python!你好,世界!",tag="mytext",font="Arial 16 bold",fill="white")
- while True:
- mycanvas.after(100)
- mycanvas.move("mytext",dx,0)
- mycanvas.update()
- if x < width :
- x =x +dx
- else :
- x = 0
- mycanvas.delete("mytext")
- mycanvas.create_text(x,50,text="你好,Python!你好,世界!",tag="mytext",font="Arial 16 bold",fill="white")
运行结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。