[英]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.