Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wxpython使用DC后擦除背景_Python_Wxpython - Fatal编程技术网

wxpython使用DC后擦除背景

wxpython使用DC后擦除背景,python,wxpython,Python,Wxpython,我无法将擦除背景事件发布到屏幕上。在我的完整代码中,我希望在单击按钮时绘制位图(DC.DrawBitmap())。我通过发布一个由自定义绑定方法捕获的EVT_ERASE_后台事件来实现这一点。但是,一旦进入该方法,正常工作的event.GetDC()方法就会失败 下面是一个具有相同结果的简化代码: import wx class Foo(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__ (se

我无法将擦除背景事件发布到屏幕上。在我的完整代码中,我希望在单击按钮时绘制位图(DC.DrawBitmap())。我通过发布一个由自定义绑定方法捕获的EVT_ERASE_后台事件来实现这一点。但是,一旦进入该方法,正常工作的event.GetDC()方法就会失败

下面是一个具有相同结果的简化代码:

import wx class Foo(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__ (self, parent, -1, title, size=(500,300)) self.panel = wx.Panel(self, -1) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_ENTER_WINDOW, self.onEnter) self.Show() def OnEraseBackground(self, e): DC = e.GetDC() def onEnter(self, e): wx.PostEvent(self, wx.PyCommandEvent(wx.wxEVT_ERASE_BACKGROUND)) app = wx.App() Foo(None, 'foo') app.MainLoop() 导入wx 类Foo(wx.Frame): 定义初始(自我、父母、头衔): wx.Frame.\uuuuu init\uuuuuuu(self,parent,-1,title,size=(500300)) self.panel=wx.panel(self,-1) self.Bind(wx.EVT_ERASE_BACKGROUND,self.OnEraseBackground) self.Bind(wx.EVT_进入_窗口,self.oneter) self.Show() def ONERASE背景(自我,e): DC=e.GetDC() def onEnter(自我,e): PostEvent(self,wx.PyCommandEvent(wx.wxEVT_ERASE_BACKGROUND)) app=wx.app() Foo(无,“Foo”) app.MainLoop() 这引起:

AttributeError: 'PyCommandEvent' object has no attribute 'GetDC' AttributeError:“PyCommandEvent”对象没有属性“GetDC”
我该如何解决这个问题呢?

在发布之前,我花了一个小时解决了这个问题,但没有成功,五分钟后我自己解决了这个问题

下面是我的解决方案,如果事件没有自己的DC,则创建ClientDC:

import wx class Foo(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__ (self, parent, -1, title, size=(500,300)) self.panel = wx.Panel(self, -1) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_ENTER_WINDOW, self.onEnter) self.Show() def OnEraseBackground(self, e): try: DC = e.GetDC() except: DC = wx.ClientDC(self) DC.Clear() def onEnter(self, e): wx.PostEvent(self, wx.PyCommandEvent(wx.wxEVT_ERASE_BACKGROUND)) app = wx.App() Foo(None, 'foo') app.MainLoop() 导入wx 类Foo(wx.Frame): 定义初始(自我、父母、头衔): wx.Frame.\uuuuu init\uuuuuuu(self,parent,-1,title,size=(500300)) self.panel=wx.panel(self,-1) self.Bind(wx.EVT_ERASE_BACKGROUND,self.OnEraseBackground) self.Bind(wx.EVT_进入_窗口,self.oneter) self.Show() def ONERASE背景(自我,e): 尝试: DC=e.GetDC() 除: DC=wx.ClientDC(自) DC.Clear() def onEnter(自我,e): PostEvent(self,wx.PyCommandEvent(wx.wxEVT_ERASE_BACKGROUND)) app=wx.app() Foo(无,“Foo”) app.MainLoop()