python - 如何使 .configure(text="lorem ipsum") 仅在给定的时间内显示(例如仅显示 5 秒)?
问题描述
现在,例如,如果我单击用户名的“复制”按钮,“用户名已复制! ”将永远显示在那里。我只希望它显示 5 秒钟,然后会再次显示“欢迎” 。description = Label(window, text="Welcome")
from tkinter import *
from urllib import parse
from tkinter import Tk
window = Tk()
window.title("CopyText")
window.geometry('295x150+600+210')
large_font = ('Verdana',11)
small_font = ('Verdana',10)
#USERNAME ===================
lbl = Label(window, text="Username:")
lbl.grid(column=0, row=0)
entry1Var = StringVar(value='myusername')
txt = Entry(window,textvariable=entry1Var,font=large_font, width=18)
txt.grid(column=1, row=0)
def clicked():
copy = txt.get()
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(copy)
description.configure(text="Username copied!")
r.update()
btn = Button(window, text="copy", command=clicked, height=2, width=5)
btn.grid(column=2, row=0)
#PASSWORD ===================
pword = Label(window, text="Password:")
pword.grid(column=0, row=4)
entry2Var = StringVar(value='mypassword')
pwordtxt = Entry(window,textvariable=entry2Var,font=large_font, width=18)
pwordtxt.grid(column=1, row=4)
def clicked():
copy = pwordtxt.get()
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(copy)
description.configure(text="Password copied!")
r.update()
btn = Button(window, text="copy", command=clicked, height=2, width=5)
btn.grid(column=2, row=4)
#EMAIL ===================
email = Label(window, text="Email:")
email.grid(column=0, row=6)
entry3Var = StringVar(value='myemail@gmail.com')
emailtxt = Entry(window,textvariable=entry3Var,font=large_font, width=18)
emailtxt.grid(column=1, row=6)
def clicked():
copy = emailtxt.get()
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(copy)
description.configure(text= "Email copied!")
r.update()
btn = Button(window, text="copy", command=clicked, height=2, width=5)
btn.grid(column=2, row=6)
description = Label(window, text="Welcome")
description.grid(column=1, row=7)
window.mainloop()
解决方案
推荐阅读
- ruby-on-rails - 资源选择器不会显示
- python - 从多天的日期时间时间戳列表中,如何找到每天的最后一个时间戳?
- javascript - 如何在 Phaser 3 中检测图形和 Sprite 之间的碰撞?
- javascript - 当我运行 ajax 加载另一个文件时,出现此错误“无法建立连接。接收端不存在”
- python-3.x - 二维数组的 Numpy 特定重塑顺序
- vue.js - VueJS 依赖属性
- javascript - 如何在角度 6 中单击它时获取 highcharts 中图表的 Div id
- sql-server - 带有变量的 SSIS 多文件加载错误
- spring - 单个弹簧轮廓的多个属性文件
- jquery - 单击一个按钮并使 div 隐藏在可折叠的手风琴中