0
我無法發佈擦除後臺事件以繪製到屏幕。在我的完整代碼中,我想在單擊按鈕時繪製位圖(DC.DrawBitmap())。我通過發佈由自定義綁定方法捕獲的EVT_ERASE_BACKGROUND事件來完成此操作。但是,一旦它在該方法中,通常工作的event.GetDC()方法將失敗。wxpython使用DC後擦除背景
這裏是具有相同結果的簡化代碼:
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()
這就提出:
AttributeError: 'PyCommandEvent' object has no attribute 'GetDC'
我該如何解決這個問題?