|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大侠,我目前在用tkinter 编写界面,用的是Python3.4,任务是在主界面上点击按钮后,会弹出一个界面,过5秒钟后,弹出界面消失。但发现点击按钮后并没有弹出界面,tkinter是基于事件触发,似乎是在按钮点击后必须执行完调用函数后,才会出现其他东西,不知道有没有什么办法可以解决。下面是我的代码,希望高手可以帮我解决,先谢过了。
import time
from tkinter import*
from tkinter import ttk
class fram1:
def __init__(self,master):
self.master=master
self.master.geometry('300x200')
Label(self.master, text="Hello!",width=20,font =('Verdana',15)).grid(row=1, column=40,sticky=N+S+W+E)
self.button1 = Button(self.master,text='Click',width =2,bd=4,state=NORMAL,command=self.click,font =('Verdana',12))
self.button1.grid(row=40,column=40,sticky=W+E+N+S)
def click(self):
fm=Tk()
splash=fram2(fm)
time.sleep(5)
splash.destroy()
class fram2:
def __init__(self,t):
self.fm=t
self.fm.title("Notice")
Label(self.fm, text="System is running",font =('Verdana',20),bg='red',width=20,height=2).grid(sticky=N+S+W+E)
Label(self.fm, text="Please Wait....",font =('Verdana',20),bg='red',width=20,height=2).grid(sticky=N+S+W+E)
def destroy(self):
self.fm.destroy()
def deiconify(self):
self.fm.deiconify()
def main():
root=Tk()
a=fram1(root)
mainloop()
if __name__ == '__main__':
main()
5秒后关闭!
- import tkinter as tk
- import time
- import threading
- def showother():
- otherFrame.update()
- otherFrame.deiconify()
- hide_thd()
- def delaysHideOther():
- time.sleep(5)
- otherFrame.withdraw()
-
- def hide_thd():
- threading.Thread(target = delaysHideOther).start()
-
- root = tk.Tk()
- otherFrame = tk.Toplevel()
- otherFrame.withdraw()
- otherFrame.attributes('-toolwindow', True)
- otherFrame.geometry('150x50')
- tk.Label(otherFrame, text="5秒后关闭!", width=50).pack()
- root.geometry('150x80')
- tk.Button(root, text='显示弹窗', width=10, command=showother).pack()
- root.mainloop()
复制代码
|
|