python-3.x - 在屏幕上放置一个 tkinter 标签几秒钟然后销毁它
问题描述
因此,当您运行 tkinter 标签(和整个窗口)下方的代码时,几秒钟内根本没有出现,然后窗口显示时没有标签。我想显示标签几秒钟,然后让它在几秒钟后消失。
from tkinter import *
import time
root = Tk()
busted_display = Label(root, text="My Label Widget",
font=("arial", "15"))
busted_display.place(x=0, y=0)
print("it ran")
time.sleep(3)
print("and then this ran")
busted_display.destroy()
root.mainloop()
解决方案
You can't use time.sleep in an event driven program like a GUI. In tkinter, the answer to timed operations is the after()
method, which runs the code you give it after a certain amount of milliseconds.
from tkinter import *
root = Tk()
busted_display = Label(root, text="My Label Widget", font=("arial", "15"))
busted_display.place(x=0, y=0)
root.after(2000, busted_display.destroy)
root.mainloop()
推荐阅读
- vue.js - Vue-cli 3组件库支持SSR
- pine-script - 我想在 pine 脚本中打印“i”的值
- discord - Discord PY 获取服务器的所有成员
- python-3.x - 每当我尝试导入 cntk 时,它都会显示 No module named 'cntk._cntk_py'
- api - 空手道模拟测试双打无法识别 headerContains 场景参数
- typescript - 类型以表示具有特定类型键的父级
- javascript - 使用节点 js 中的猫鼬创建分片集合
- javascript - 全新 TypeScript,尝试使用 Sequelize
- c# - 为什么某些应用程序无法调用“刷新”来查看文件更新?
- javascript - jQuery如何区分哪个“