问题描述
我正在使用wxpython开发一个多平台应用程序,在Panel上绘图时,在Windows上出现了闪烁问题.我曾经在鼠标移动事件期间在缓冲区(wx.Bitmap)上绘制,而我的OnPaint方法仅由在线组成:
I'm working on an multiplatform application with wxpython and I had flickering problems on windows, while drawing on a Panel.I used to draw on a buffer (wx.Bitmap) during mouse motions events and my OnPaint method was composed of just on line:
dc = wx.BufferedPaintDC(self, self.buffer)
相当标准,但是在Windows上我仍然有闪烁的问题,而在Linux上一切正常.
Pretty standard but still I had flickering problems on Windows, while everything worked fine on Linux.
我解决了我的问题,在__init__
方法中调用了SetDoubleBuffered(True)
.
奇怪的是,即使我不再使用BufferedPaintDC,现在一切都可以使用.我更改了应用程序,以便所有绘图部分都在OnPaint方法中完成.我不使用缓冲区,而是直接在wx.PaintDC上完成绘制,完全没有闪烁问题.
The strange thing is that now everything works even if I don't use BufferedPaintDC anymore. I changed my application so that all the drawing part is done in the OnPaint method. I don't use a buffer and drawing is done directly on a wx.PaintDC with no flickering problems at all.
所以我的问题是:BufferedPaintDC完全没用吗?还是不赞成使用?我是《 WxPython in Action》(2006年)一书的所有者,甚至没有提到SetDoubleBuffered
So my question is: is BufferedPaintDC totally useless? Or deprecated somehow? I'm owner of the book "WxPython in Action" (2006) and it doesn't even mention SetDoubleBuffered
推荐答案
很有可能SetDoubleBuffered实际上使您的面板自动使用缓冲的dc,文档中没有提到那些类已被弃用(我宁愿认为是这样的话.
There is a high probability that the SetDoubleBuffered actually makes your panel use a buffered dc automatically, the documentation doesn't mention that those classes are deprecated (and I rather think they would if that were the case).
关于wxPython的实际应用...很久以前,2006年...当时可能还没有SetDoubleBuffered方法,或者作者想展示下层的工作原理.
About wxPython in Action... 2006 was a long time ago... it is possible that the SetDoubleBuffered method didn't exist back then or that the author wanted to show how things work at the lower level.
这篇关于用wxpython进行双缓冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!