鱼C论坛

 找回密码
 立即注册
查看: 6766|回复: 5

[已解决]tkinter 弹出界面问题

[复制链接]
发表于 2016-7-29 22:59:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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()
最佳答案
2016-7-30 17:10:01
adamxuwx 发表于 2016-7-30 16:31
谢谢版主回复,不过你的例子只是单个界面,我要实现的是两个界面。

5秒后关闭!
  1. import tkinter  as tk
  2. import time
  3. import threading

  4. def showother():
  5.     otherFrame.update()
  6.     otherFrame.deiconify()
  7.     hide_thd()

  8. def delaysHideOther():
  9.     time.sleep(5)
  10.     otherFrame.withdraw()
  11.    
  12. def hide_thd():
  13.     threading.Thread(target = delaysHideOther).start()
  14.    
  15. root = tk.Tk()

  16. otherFrame = tk.Toplevel()
  17. otherFrame.withdraw()
  18. otherFrame.attributes('-toolwindow', True)
  19. otherFrame.geometry('150x50')
  20. tk.Label(otherFrame, text="5秒后关闭!", width=50).pack()

  21. root.geometry('150x80')
  22. tk.Button(root, text='显示弹窗', width=10, command=showother).pack()

  23. root.mainloop()
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-7-30 07:06:54 | 显示全部楼层
代码一定要用代码格式发布
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-7-30 07:29:44 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-7-30 16:31:31 | 显示全部楼层
谢谢版主回复,不过你的例子只是单个界面,我要实现的是两个界面。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-7-30 17:10:01 | 显示全部楼层    本楼为最佳答案   
adamxuwx 发表于 2016-7-30 16:31
谢谢版主回复,不过你的例子只是单个界面,我要实现的是两个界面。

5秒后关闭!
  1. import tkinter  as tk
  2. import time
  3. import threading

  4. def showother():
  5.     otherFrame.update()
  6.     otherFrame.deiconify()
  7.     hide_thd()

  8. def delaysHideOther():
  9.     time.sleep(5)
  10.     otherFrame.withdraw()
  11.    
  12. def hide_thd():
  13.     threading.Thread(target = delaysHideOther).start()
  14.    
  15. root = tk.Tk()

  16. otherFrame = tk.Toplevel()
  17. otherFrame.withdraw()
  18. otherFrame.attributes('-toolwindow', True)
  19. otherFrame.geometry('150x50')
  20. tk.Label(otherFrame, text="5秒后关闭!", width=50).pack()

  21. root.geometry('150x80')
  22. tk.Button(root, text='显示弹窗', width=10, command=showother).pack()

  23. root.mainloop()
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-7-30 17:47:44 | 显示全部楼层
果然高手啊,已经解决了,谢谢啊!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-22 00:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表