0
我正在制作一个程序python(Tkinter)以某种方式我卡在一些混淆之间。 我想暂停我的程序执行几秒钟,并且执行暂停但不是在正确的时间。 我的计划是这样的:如何暂停程序几秒钟
from Tkinter import *
from time import *
root=Tk()
def login():
g=str(ent.get())
h=str(ent2.get())
if h=='shubhank' and g=='shubhankt1':
root2=Tk()
root2.title("Shubhank Tyagi")
root2.geometry('300x300')
root2.wm_iconbitmap('st.ico')
name=Label(root2, text='''Name: Shubhank Tyagi
Age: 18 yrs
Sex: Male
Occupation: Student
Designation: Intermediate''')
name.pack()
elif h=='divyansh' and g=='divyansht5':
root2=Tk()
root2.title("Divyansh Tyagi")
root2.geometry('300x300')
root2.wm_iconbitmap('st.ico')
name=Label(root2, text='''Name: Divyansh Tyagi
Age: 18 yrs
Sex: Male
Occupation: Student
Designation: Intermediate''')
name.pack()
else:
error=Label(root, text='Please provide correct info.')
error.pack()
sleep(5)
error.pack_forget()
w=Label(root, text="Username", bg='Light Blue')
ent=Entry(root)
w2=Label(root, text="Password", bg='Light Blue')
ent2=Entry(root)
ent2.config(show=' ')
btn=Button(root, text='Click Me!', command=login)
该按钮(BTN)调用定义的函数。 我想要的是tht首先tht错误msg被打印..并且在某个时候它被删除..在点击按钮之后发生问题,程序暂停nd直接返回error.pack_forget()函数被执行..和错误信息从未打印...
请帮帮我!
(我也可以提供实际的Python文件,如果需要)
我认为你需要调用'error.update_idletasks()''之前睡觉(5)'这将更新显示_before_应用程序下一步空转,这是当它通常做的。应用程序在更新显示并等待新事件后通常处于空闲状态,但对“睡眠”的调用阻止了这种情况的发生。 – martineau