By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,530 Members | 1,576 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,530 IT Pros & Developers. It's quick & easy.

what's wrong with this if statement?

P: n/a
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.
Jul 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jul 21 '06 #2

P: n/a
Philippe Martin wrote:
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.
Ah, of course! Thanks!
Jul 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.