(Tkinter)试图在循环中更新进度条值但程序崩溃了?
(Tkinter) Trying to updated progress bar value in loop but crashed program?
我只想在单击按钮时填充进度条,但每次单击按钮时它都会崩溃,而且我的控制台没有任何错误
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import ttk
from time import sleep
window = Tk()
window.title("Gui Testing")
window.geometry("350x200")
style = ttk.Style()
style.theme_use("default")
style.configure("black.Horizontal.TProgressbar",background="black")
bar = Progressbar(window,length=200,style="black.Horizontal.TProgressbar")
bar["value"] = 0
bar.grid(column=0,row=0)
def prog():
i = 0
while i <= 100:
sleep(.5)
i = i + 1
bar["value"] = i
btn = Button(text="Click",command=prog)
btn.grid(column=0,row=1)
window.mainloop()
尝试设置:
ttk.Progressbar(window,length=200,style="black.Horizontal.TProgressbar", mode="determinate")
我只想在单击按钮时填充进度条,但每次单击按钮时它都会崩溃,而且我的控制台没有任何错误
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import ttk
from time import sleep
window = Tk()
window.title("Gui Testing")
window.geometry("350x200")
style = ttk.Style()
style.theme_use("default")
style.configure("black.Horizontal.TProgressbar",background="black")
bar = Progressbar(window,length=200,style="black.Horizontal.TProgressbar")
bar["value"] = 0
bar.grid(column=0,row=0)
def prog():
i = 0
while i <= 100:
sleep(.5)
i = i + 1
bar["value"] = i
btn = Button(text="Click",command=prog)
btn.grid(column=0,row=1)
window.mainloop()
尝试设置:
ttk.Progressbar(window,length=200,style="black.Horizontal.TProgressbar", mode="determinate")