#! /usr/bin/env python
#coding=utf-8
import wx
class MouseEventFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Frame With Button ',size=(300,100))
self.panel = wx.Panel(self)
self.button = wx.Button(self.panel,label='Not Over',pos=(100,15))
self.Bind(wx.EVT_BUTTON,self.OnButtonClick,self.button)
#鼠标进入事件不是wx.CommondEvent的子类,所以鼠标进入事件不向
#上扩展至容器,所以只能绑定到按钮
self.button.Bind(wx.EVT_ENTER_WINDOW,self.OnEnterWindow)
self.button.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeaveWindow)
#此方法不会被调用
self.Bind(wx.EVT_ENTER_WINDOW,self.OnWindowEnter,self.button)
def OnButtonClick(self,event):
self.panel.SetBackgroundColour('Green')
self.panel.Refresh()
def OnEnterWindow(self,event):
self.button.SetLabel("Over Me!")
event.Skip()
def OnLeaveWindow(self,event):
self.button.SetLabel("Not Over")
event.Skip()
def OnWindowEnter(self,event):
self.button.SetLabel("Over Me Again!")
self.panel.SetBackgroundColour('Red')
self.panel.Refresh()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MouseEventFrame(parent= None,id=-1)
frame.Show()
app.MainLoop()
阅读(568) | 评论(0) | 转发(0) |