I am having trouble posting an erase background event to draw to the screen. In my full code, I want to draw a bitmap (DC.DrawBitmap()) when a button is clicked. I do that by posting an EVT_ERASE_BACKGROUND event which is caught by a custom bound method. However, once it is in that method, the event.GetDC() method that normally works fails.
Here is a simplified code that has the same result:
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()
This raises:
AttributeError: 'PyCommandEvent' object has no attribute 'GetDC'
How can I solve this?