[Tutor] Problems with Gauge Bar.

Alan Gauld alan.gauld at btinternet.com
Fri Aug 22 02:35:45 CEST 2008


"Olrik Lenstra" <o.lenstra at gmail.com> wrote

>>    def onScan(self, event):
>>>       self.myfile = open('foo.txt')
>>>       self.count = 0
>>>       self.setTimer(0.01, self.processLine)
>
> Ah, I got this mixed up. I thought this was a function built into 
> python.
> So I would need to define setTimer in the MyClass too.
> Is there anything that I can read on timers?

The wx documentation on timers is OK. Here is a very short
example program

import wx

class Counter(wx.Window):
   def __init__(self,  interval=1000):  # default of 1 second
       self.count = 0
       self.t = wx.Timer(self)
       self.Bind(wx.EVT_TIMER, self.onTimer, self.t)
       self.t.Start(interval, oneShot = True)

   def onTimer(self, evt):
       self.upDate()
       self.t.Start(-1, oneShot=True)

   def upDate(self):
      self.count += 1
      print "Called by timer event ", self.count

class App(wx.Frame):
     def __init__(self):
         wx.Frame.__init__(self,None)
         Counter(self)

p = wx.PySimpleApp()
f = App()
f.Show()
p.mainloop()


Note this is untested since I don't have wx installed on this PC,
but it should be close. You can also use Start(delay, oneShot=False)
to create a continuously firing timer.

HTH,

Alan G 




More information about the Tutor mailing list