简体   繁体   English

如何使wxPython应用程序不断更新和执行代码?

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

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. 我希望圆圈在屏幕周围弹起,但是我无法弄清楚更改x和y变量的位置。

您可以使用wxTimer定期调用onTimer(self)方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM