我有这个简单的代码,它运行一个进度条15秒。 我想要的是当进度条达到15秒来调用一个函数或打印一些东西并且该栏保持填充在屏幕上,而不是重置并再次进入循环
感谢adavnce
import Tkinter
import ttk
def main():
root = Tkinter.Tk()
ft = ttk.Frame()
ft.pack(expand=True, fill=Tkinter.BOTH, side=Tkinter.TOP)
pb_hd = ttk.Progressbar(ft, orient='horizontal', mode='determinate')
pb_hd.pack(expand=True, fill=Tkinter.BOTH, side=Tkinter.TOP)
pb_hd.start(150)
root.mainloop()
if __name__ == '__main__':
main()
答案 0 :(得分:0)
让我说,这个目的对我来说有点模糊......无论如何,有很多方法可以做你所问的。一个可能是以下内容:
from threading import Thread
from time import sleep
import Tkinter
import ttk
def on_loading(widget, value, loading_end):
print 'loading...'
widget.start(150)
sleep(15)
widget.stop()
value(100)
on_ready()
def on_ready():
print "now ready to work..."
def main():
root = Tkinter.Tk()
ft = ttk.Frame()
ft.pack(expand=True, fill=Tkinter.BOTH, side=Tkinter.TOP)
value = 0 #the value of the progressbar
setvalue = lambda x,value=value: value+x #the lambda to capture value
pb_hd = ttk.Progressbar(ft, orient='horizontal', mode='determinate', max=100.0, variable=value)
pb_hd.pack(expand=True, fill=Tkinter.BOTH, side=Tkinter.TOP)
#Creates a thread that call on_loading
Thread(target=on_loading, args=(pb_hd, setvalue, on_loading_end)).start()
root.mainloop()
if __name__ == '__main__':
main()