[英]Manual progress bar python
我正在尝试编写代码,以便显示从1到100的所有数字,以显示正在加载的内容。
for i in range(101):
self.new = Label(self.label_progress, text=i)
time.sleep(1)
self.new.place(in_= self.label_progress)
if i == 100:
self.new1=Label(self.label_progress, text="the download is complete")
self.new1.place(in_=self.label_progress, x=50)
但是似乎不希望在循环完成前显示每个数字,最后只显示100。如何解决此问题的任何建议?
tkinter
具有mainloop()
它运行所有的时间,做了很多事情-即。 它会更新小部件中的数据,重绘小部件,执行您的功能。 当mainloop()
执行函数时,直到函数停止运行,它才能更新/重绘窗口小部件。 您可以在函数中使用root.update()
强制tkinter更新/重新绘制窗口小部件。
或者你可以使用
root.after(miliseconds, function_name)
定期执行将更新Label
功能。 在两次执行之间, tkinter
将有时间更新/重绘窗口小部件。
在Label
更新时间after
使用的示例:
https://github.com/furas/my-python-codes/tree/master/tkinter/timer-using-after
BTW: tkinter
有ttk.Progressbar
示例代码: https : //stackoverflow.com/a/24770800/1832058
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.