【发布时间】:2011-01-19 08:16:48
【问题描述】:
使用此代码:
import wx
class Plugin(wx.Panel):
def __init__(self, parent, *args, **kwargs):
panel = wx.Panel.__init__(self, parent, *args, **kwargs)
self.colorOver = ((89,89,89))
self.colorLeave = ((110,110,110))
self.colorFont = ((145,145,145))
self.SetBackgroundColour(self.colorLeave)
self.SetForegroundColour(self.colorLeave)
self.name = "Plugin"
self.overPanel = 0
self.overLabel = 0
self.overButton = 0
sizer = wx.BoxSizer(wx.VERTICAL)
self.pluginName = wx.StaticText(self, -1, ' ' + self.getName())
self.pluginClose = wx.BitmapButton(self, -1, wx.Bitmap('C:\Users\André Ferreira\Desktop\Tese\Código Python\SoundLog\Images\close.png'), style=wx.NO_BORDER)
self.pluginClose.Hide()
gs = wx.GridSizer(2, 2, 0, 0)
gs.AddMany([(self.pluginName, 0, wx.ALIGN_LEFT), (self.pluginClose, 0, wx.ALIGN_RIGHT|wx.CENTER)])
sizer.Add(gs, 1, wx.EXPAND)
self.SetSizer(sizer)
self.pluginName.Bind(wx.EVT_LEAVE_WINDOW, self.onLabelMouseLeave)
self.pluginName.Bind(wx.EVT_ENTER_WINDOW, self.onLabelMouseOver)
self.pluginClose.Bind(wx.EVT_BUTTON, self.onCloseMouseClick)
self.Bind(wx.EVT_LEAVE_WINDOW, self.onPanelMouseLeave)
self.Bind(wx.EVT_ENTER_WINDOW, self.onPanelMouseOver)
def onPanelMouseOver(self, event):
self.overPanel = 1
self.overLabel = 0
self.SetBackgroundColour(self.colorOver)
self.pluginName.SetForegroundColour(self.colorFont)
self.Refresh()
self.pluginClose.Show()
def onPanelMouseLeave(self, event):
if self.overLabel == 0:
self.overPanel = 0
self.SetBackgroundColour(self.colorLeave)
self.pluginName.SetForegroundColour(self.colorLeave)
self.Refresh()
self.pluginClose.Hide()
def onLabelMouseOver(self, event):
self.overPanel = 0
self.overLabel = 1
self.SetBackgroundColour(self.colorOver)
self.pluginName.SetForegroundColour(self.colorFont)
self.Refresh()
self.pluginClose.Show()
def onLabelMouseLeave(self, event):
if self.overPanel == 0:
self.overLabel = 0
self.SetBackgroundColour(self.colorLeave)
self.pluginName.SetForegroundColour(self.colorLeave)
self.Refresh()
self.pluginClose.Hide()
def OnClose(self, event):
self.Close()
app.Destroy()
def onCloseMouseClick(self, event):
self.Hide()
def getName(self):
return self.name
每当我越过 BitmapButton 时,接下来的两个事件:
self.Bind(wx.EVT_LEAVE_WINDOW, self.onPanelMouseLeave)
self.Bind(wx.EVT_ENTER_WINDOW, self.onPanelMouseOver)
总是被呼叫。
它有什么问题?怎么只能调用一个事件呢?
注意:如果我将离开和输入窗口事件绑定到 BitmapButton 之前的两个事件仍然会被调用。
【问题讨论】:
标签: python events button wxpython panel