wxpython:如何在窗口被修复时重绘某些内容?

时间:2021-10-07 07:17:07

In my wx.Frame based wxpython application, I draw some lines on a panel when some events occur by creating wx.ClientDC instances when needed. The only problem is, if the window is minimized and then restored, the lines disappear! Is there some kind of method that I should override or event to bind to that will allow me to call the drawing method I created when the window is restored?

在我的基于wx.Frame的wxpython应用程序中,当某些事件发生时,我通过在需要时创建wx.ClientDC实例来在面板上绘制一些行。唯一的问题是,如果窗口最小化然后恢复,线条会消失!是否有某种方法我应该覆盖或绑定到的事件将允许我调用我在窗口恢复时创建的绘图方法?

Thanks!

2 个解决方案

#1


only place you must be drawing is on wx.EVT_PAINT, so bind to that event in init of panel e.g.

只有你必须绘制的地方是在wx.EVT_PAINT上,所以在init的面板中绑定到该事件,例如

self.Bind(wx.EVT_PAINT, self._onPaint)

in _onPaint, use wx.PaintDC to to draw e.g.

在_onPaint中,使用wx.PaintDC来绘制例如

dc = wx.PaintDC(self)
dc.DrawLine(0,0,100,100)

#2


When the window is restored it is (on some platforms) repainted using EVT_PAINT handler.

当窗口恢复时,它(在某些平台上)使用EVT_PAINT处理程序重新绘制。

The solution is e.g. to draw the same lines in OnPaint(). Or buffer what you draw. See the wxBufferedDC class.

解决方案是例如在OnPaint()中绘制相同的行。或缓冲你画的东西。请参阅wxBufferedDC类。

#1


only place you must be drawing is on wx.EVT_PAINT, so bind to that event in init of panel e.g.

只有你必须绘制的地方是在wx.EVT_PAINT上,所以在init的面板中绑定到该事件,例如

self.Bind(wx.EVT_PAINT, self._onPaint)

in _onPaint, use wx.PaintDC to to draw e.g.

在_onPaint中,使用wx.PaintDC来绘制例如

dc = wx.PaintDC(self)
dc.DrawLine(0,0,100,100)

#2


When the window is restored it is (on some platforms) repainted using EVT_PAINT handler.

当窗口恢复时,它(在某些平台上)使用EVT_PAINT处理程序重新绘制。

The solution is e.g. to draw the same lines in OnPaint(). Or buffer what you draw. See the wxBufferedDC class.

解决方案是例如在OnPaint()中绘制相同的行。或缓冲你画的东西。请参阅wxBufferedDC类。