473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

what's wrong with this if statement?

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
2 1085
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
6
by: Daniel Rudy | last post by:
What is wrong with this program? When I try to compile it, I get the following error. Compiler is gcc on FreeBSD. strata:/home/dcrudy/c 1055 $$$ ->cc -g -oe6-3 e6-3.c e6-3.c: In function...
8
by: Brian Basquille | last post by:
Hello all, Bit of a change of pace now. As opposed to the typical questions regarding my Air Hockey game, am also working on a Photo Album which uses an Access Database to store information...
1
by: THY | last post by:
can anyone tell me what's wrong with this statement ? cn.execute("update table set data = 'test'") the asp.net keep telling me syntax error in update statement ... help me please ...
22
by: noridotjabi | last post by:
Okay. I'm quite embarased to be asking this but I cannot seem to get files to work. I don't know what the problem is. Is there something wrong with this: (file related) #include <stdio.h>...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
5
by: Ryan | last post by:
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder Creek","STATE":"CA","DIST":5745.4} I get an "invalid label" error... I'm kinda new to this. Thanks!
15
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str,...
6
by: CTG | last post by:
"update set UPDATE-FLAG=false, UPDATE-DT= '10/09/2007 4:09:59 PM' WHERE ICCID='I1' " UPDATE_FLAG is a YES/NO ICCID is TEXT I have tried YES, NO as well but still fails,
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.