2010-02-16 27 views
5

mã này:Làm thế nào để thay đổi màu nền wx.Panel trên MouseOver?

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() 

mang lại cho tôi những lỗi:

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' 

Tôi đang làm gì sai? P .: Tôi cần phải có lớp này như là một wx.Panel!

Cảm ơn trước

Trả lời

12

Phương thức có tên SetBackgroundColour, với u.

Ngoài ra, bạn đang liên kết các sự kiện hai lần với hai phương pháp khác nhau. Chỉ cần sử dụng kiểu self.Bind và xóa hai dòng còn lại.

+0

omg, cảm ơn m8 lol :( –

Các vấn đề liên quan