我有以下代码:
import time, os
from tkinter import *
class Chat():
def sPrint():
s=0
while s < 11:
s+=1
print (s, 'Sec')
time.sleep(1)
if s ==5:
print ("5..")
myapp.OpenWindow1()
if s ==10:
print ("10..")
myapp.OpenWindow2()
class App(Frame):
def ConnectButton1(self):
self.con1 = Button(self)
self.con1["text"] = "Connect1",
self.con1["command"] = lambda: Chat.sPrint()
self.con1.grid(row=0,column=2,padx=5, pady=3,sticky=W)
def OpenWindow1(self):
win1 = Toplevel()
def OpenWindow2(self):
win2 = Toplevel()
myapp = App()
if __name__ == "__main__":
myapp.ConnectButton1()
myapp.pack()
myapp.mainloop()
问题是 - “打印”从循环内部每隔5秒完美运行, 但是Toplevel函数只在“while”结束时运行(然后显示两个 同时顶出窗户)
当我使用
时也是如此threading.Timer(1, sPrint1).start()
在循环中运行函数..我无法加载新的tkinter按钮/标签 当函数处于循环中时。
有什么建议吗?