如何在MouseOver上更改wx.Panel背景颜色?

aF.*_*aF. 5 python wxwidgets wxpython 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()
Run Code Online (Sandbox Code Playgroud)

给我错误:

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'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?PS:我需要把这个课作为wx.Panel!

提前致谢

Fog*_*ird 12

该方法以SetBackgroundColouru 命名.

此外,您使用两种不同的方法绑定事件两次.只需使用self.Bind样式,然后删除其他两行.