John Salerno wrote: > Here's the full code, but you can probably safely ignore most of it, > especially the wxPython stuff: > > ----------------------------------- > > import wx > > > class MyFrame(wx.Frame): > > def __init__(self): > wx.Frame.__init__(self, parent=None, id=wx.ID_ANY) > panel = wx.Panel(self) > > mainSizer = wx.BoxSizer(wx.VERTICAL) > inputSizer = wx.BoxSizer(wx.HORIZONTAL) > > self.count = 0 > self.progress = wx.Gauge(panel, wx.ID_ANY, 100, size=(300, 20)) > self.status = wx.StaticText(panel, wx.ID_ANY, 'test') > prompt = wx.StaticText(panel, wx.ID_ANY, 'Time:') > self.input = wx.TextCtrl(panel, wx.ID_ANY, size=(20, 20)) > self.start = wx.Button(panel, wx.ID_ANY, 'Start') > self.timer = wx.Timer(self) > > mainSizer.Add(self.progress, flag=wx.ALIGN_CENTER | wx.TOP, > border=10) > mainSizer.Add(self.status, flag=wx.ALIGN_CENTER | wx.ALL, > border=10) > mainSizer.Add(inputSizer, flag=wx.ALIGN_CENTER) > inputSizer.Add(prompt, flag=wx.ALIGN_CENTER) > inputSizer.Add(self.input, flag=wx.ALL, border=10) > inputSizer.Add(self.start, flag=wx.ALIGN_CENTER) > > self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) > self.Bind(wx.EVT_BUTTON, self.OnStart, self.start) > > panel.SetSizer(mainSizer) > > def OnStart(self, event): > self.time = self.input.GetValue() > self.timer.Start(1000) > > def OnTimer(self, event): > self.count += 1 > if self.count < self.time: > self.progress.SetValue(self.count) > self.status.SetLabel(str(self.count)) > > > class MyApp(wx.App): > > def OnInit(self): > frame = MyFrame() > self.SetTopWindow(frame) > frame.Show() > return True > > > if __name__ == '__main__': > app = MyApp(redirect=False) > app.MainLoop() > > ------------------------------------ > > The code in question is mainly this: > > def OnTimer(self, event): > self.count += 1 > if self.count < self.time: > self.progress.SetValue(self.count) > self.status.SetLabel(str(self.count)) > > When I run the program, the progress bar and the status label continue > to increase even after self.count has (presumably) become larger than > self.time. Why is this? All I do is enter in '10' as the value to test > it, and it keeps counting even beyond 10.
Check the type of self.time: unicode - you need to convert it to int first ... plus your timer will need to be shutdown when you're done. Regards, Philippe -- http://mail.python.org/mailman/listinfo/python-list