开发者

How can I make a wxPython app constantly update and execute code?

Given the following simple program:

import wx

class TestDraw(wx.Panel):
  开发者_如何学Python  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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜