用 TK 写的状态条为何不能实时显示出状态 ?
class ProgressBar:
def __init__(self, Parent, Height=14, Width=100, ForegroundColor=None, BackgroundColor=None, Progress=0):
self.Height = Height
self.Width = Width
self.BarCanvas = Tkinter.Canvas(Parent, width=Width, height=Height, background=BackgroundColor, borderwidth=1, relief=Tkinter.SUNKEN)
if (BackgroundColor):
self.BarCanvas['backgroundcolor'] = BackgroundColor
self.BarCanvas.pack(expand=Tkinter.YES, fill=Tkinter.X, padx=0, pady=0)
self.RectangleID = self.BarCanvas.create_rectangle(0,0,0,Height)
if (ForegroundColor == None):
ForegroundColor = "black"
self.BarCanvas.itemconfigure(self.RectangleID, fill=ForegroundColor)
self.SetProgressPercent(Progress)
self.SetProgressPercent(int(item))
def SetProgressPercent(self, NewLevel):
self.Progress = NewLevel
self.Progress = min(100, self.Progress)
self.Progress = max(0, self.Progress)
self.DrawProgress()
def DrawProgress(self):
rogressPixel = (self.Progress/100.0)*self.Width
self.BarCanvas.coords(self.RectangleID, 0, 0, ProgressPixel, self.Height)
def GetProgressPercent(self):
return self.Progress
|
调用:
self.root = Tkinter.Tk()
MainFrame = Tkinter.Frame(self.root)
self.Bar = ProgressBar(MainFrame)
....
self.Bar.SetProcessPercent(10)
在程序中做别的事情的时候,调用self.Bar.SetProcessPercent时屏幕上并不显示当时的进度条,都完成了才显示出来,改成线程模式也不行 。。。这是为何?
谢谢