what's wrong with this if statement?

John Salerno johnjsal at NOSPAMgmail.com
Fri Jul 21 15:23:48 EDT 2006


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.



More information about the Python-list mailing list