Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change wx.Panel background color on MouseOver?

this code:

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

gives me the error:

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'

What am I doing wrong? P.S.: I need to have this class as a wx.Panel!

Thanks in advance

like image 566
aF. Avatar asked Feb 16 '10 20:02

aF.


1 Answers

The method is named SetBackgroundColour, with a u.

Also, you're binding events twice with two different methods. Just use the self.Bind style, and remove the other two lines.

like image 121
FogleBird Avatar answered Oct 23 '22 20:10

FogleBird