首页 > 解决方案 > 如何使 .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()

标签: pythonuser-interfacetkinter

解决方案


推荐阅读