2010-02-16 26 views
5

此代碼:如何更改MouseOver上的wx.Panel背景顏色?

import wx 

app = None 

class Plugin(wx.Panel): 
    def __init__(self, parent, *args, **kwargs): 
     wx.Panel.__init__(self, parent, *args, **kwargs) 
     self.SetBackgroundColour((11, 11, 11)) 
     self.name = "plugin" 

     self.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) 
     self.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) 

     wx.EVT_ENTER_WINDOW(self, self.onMouseOver) 
     wx.EVT_LEAVE_WINDOW(self, self.onMouseLeave) 

    def onMouseOver(self, event): 
     self.SetBackgroundColor((179, 179, 179)) 
     self.Refresh() 

    def onMouseLeave(self, event): 
     self.SetBackgroundColor((11, 11, 11)) 
     self.Refresh() 

    def OnClose(self, event): 
     self.Close() 
     app.Destroy() 

    def name(): 
     print self.name 


app = wx.App() 
frame = wx.Frame(None, -1, size=(480, 380)) 
Plugin(frame) 
frame.Show(True) 
app.MainLoop() 

給我的錯誤:

Traceback (most recent call last): 
    File "C:\.... ... ....\plugin.py", line 18, in onMouseOver 
    self.SetBackgroundColor((179, 179, 179)) 
AttributeError: 'Plugin' object has no attribute 'SetBackgroundColor' 

我在做什麼錯? P.S .:我需要把這個類作爲wx.Panel!

在此先感謝

回答

12

的方法被命名爲SetBackgroundColour,與U形。

另外,您使用兩種不同的方法綁定事件兩次。只需使用self.Bind風格,並刪除其他兩行。

+0

omg,謝謝m8 lol :( – 2010-02-16 20:14:16