我的 wx.OnPaint() 函数没有在 wx 主循环中不断调用
My wx.OnPaint() function is not called constantly in the wx main loop
我正在处理一个使用 OpenGL 和 wxPython 制作可导航 3D 用户界面的项目。
但是, OnPaint()
函数似乎并没有在主循环中连续调用。这使得我的界面不会不断更新。该函数只调用了我拖动window。例如:当我按下箭头键时,window 中的对象只有在我拖动 window 时才会移动。
我将我的代码归结为这些代码行。任何人都可以帮助我在打印一堆 "HI" 时不断调用 OnPaint()
函数,而无需拖拽 window 吗?
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame()
frame.Show()
return True
class MyFrame(wx.Frame):
def __init__(self):
self.size = (1000, 700)
wx.Frame.__init__(self, None, title ="wx", size=self.size)
self.canvas = MyCanvas(self)
class MyCanvas(GLCanvas):
def __init__(self, parent):
GLCanvas.__init__(self, parent, -1, size=(1000, 700))
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, event):
print("HI")
像wx.Frame
或GLCanvas
这样的wx.Window
可以被.Refresh()
强制重绘。
例如您可以使用 wx.IdleEvent
来触发 canvas 持续刷新。
class MyFrame(wx.Frame):
def __init__(self):
self.size = (1000, 700)
wx.Frame.__init__(self, None, title ="wx", size=self.size)
self.canvas = MyCanvas(self)
self.Bind(wx.EVT_IDLE, self.OnIdle)
def OnIdle(self, event):
self.Refresh() # refresh self and all its children
#self.canvas.Refresh() # refresh self.canvas
我正在处理一个使用 OpenGL 和 wxPython 制作可导航 3D 用户界面的项目。
但是, OnPaint()
函数似乎并没有在主循环中连续调用。这使得我的界面不会不断更新。该函数只调用了我拖动window。例如:当我按下箭头键时,window 中的对象只有在我拖动 window 时才会移动。
我将我的代码归结为这些代码行。任何人都可以帮助我在打印一堆 "HI" 时不断调用 OnPaint()
函数,而无需拖拽 window 吗?
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame()
frame.Show()
return True
class MyFrame(wx.Frame):
def __init__(self):
self.size = (1000, 700)
wx.Frame.__init__(self, None, title ="wx", size=self.size)
self.canvas = MyCanvas(self)
class MyCanvas(GLCanvas):
def __init__(self, parent):
GLCanvas.__init__(self, parent, -1, size=(1000, 700))
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, event):
print("HI")
像wx.Frame
或GLCanvas
这样的wx.Window
可以被.Refresh()
强制重绘。
例如您可以使用 wx.IdleEvent
来触发 canvas 持续刷新。
class MyFrame(wx.Frame):
def __init__(self):
self.size = (1000, 700)
wx.Frame.__init__(self, None, title ="wx", size=self.size)
self.canvas = MyCanvas(self)
self.Bind(wx.EVT_IDLE, self.OnIdle)
def OnIdle(self, event):
self.Refresh() # refresh self and all its children
#self.canvas.Refresh() # refresh self.canvas