views:

50

answers:

1

Given the following simple program:

import wx

class TestDraw(wx.Panel):
    def __init__(self,parent=None,id=-1):
        wx.Panel.__init__(self,parent,id,style=wx.TAB_TRAVERSAL)
        self.SetBackgroundColour("#FFFFFF")
        self.Bind(wx.EVT_PAINT,self.onPaint)
        self.SetDoubleBuffered(True)
        self.circleX=320
        self.circleY=240

    def onPaint(self, event):
        event.Skip()
        dc=wx.PaintDC(self)
        dc.BeginDrawing()
        dc.DrawCircle(self.circleX,self.circleY,100)
        dc.EndDrawing()

class TestFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(640,480))
        self.mainPanel=TestDraw(self,-1)

        self.Show(True)


app = wx.App(False)
frame = TestFrame(None,"Test App")
app.MainLoop()

How can I change it so that I can execute logic and repaint the panel at a constant rate? I'd like the circle to bounce around the screen, but I just can't figure out the place I would change its x and y variables.

+2  A: 

Your can use a wxTimer to periodically call an onTimer(self) method.

Ber