wxPython - drawing without paint event

7stud bbxx789_05ss at yahoo.com
Fri Aug 10 05:40:13 EDT 2007


On Aug 9, 7:46 pm, Matt Bitten <mbitte... at yahoo.com> wrote:
> I've got a wxPython program that needs to do some drawing on a DC on a
> regular basis.... And there is no event,
> so my code doesn't get called. What do I do?

Then the event is: "on a regular basis", i.e. the passage of time.
You can use a wx.Timer to create events at regular intervals, which
your code can respond to:

-------
import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "My Window")

        panel = wx.Panel(self, -1)
        self.text = wx.StaticText(panel, -1, "hello", pos=(40, 40) )

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.on_timer_event)
        self.timer.Start(milliseconds=1000, oneShot=False)

    def on_timer_event(self, event):
        if self.text.GetLabel() == "hello":
            self.text.SetLabel("goodbye")
        else:
            self.text.SetLabel("hello")


app = wx.App(redirect=False)

win = MyFrame()
win.Show()

app.MainLoop()
----------------

Make sure you save the timer in self so that you have a permanent
reference to the object, otherwise the timer will be destroyed when
__init_ returns.







More information about the Python-list mailing list