如何更改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'
我做错了什么? PS:我需要这个类作为wx.Panel!
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该方法名为
SetBackgroundColour
,带有 u。此外,您使用两种不同的方法绑定事件两次。只需使用 self.Bind 样式,并删除其他两行。
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.