相关学习内容:
Python Tkinter 绘图项目 - 网易云课堂study.163.com
import time
import tkinter
import threading
root=tkinter.Tk()
root.title('倒计时自动关闭的窗口')
root['width']=400
root['height']=300
root.resizable(False,False)
richText=tkinter.Text(root,width=380)
richText.place(x=10,y=10,width=380,height=230)
richText.insert('0.0','假设阅读这些文字需要10秒钟时间')
lbTime=tkinter.Label(root,fg='red',anchor='w')
lbTime.place(x=10,y=250,width=150)
def autoClose():
for i in range(10):
lbTime['text']='距离窗口关闭还有{}秒'.format(10-i)
time.sleep(1)
root.destroy()
t=threading.Thread(target=autoClose)
t.start()
root.mainloop()
效果图如下:Python Tkinter 绘图项目 - 网易云课堂效果图如下:
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5CMiljM4EzMmNGNxU2NzQTNhZ2M4gTNyYTNkBzNjZzYx8CX0JXZ252bj91Ztl2Lc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)