首页 > 代码库 > wxpyhon 鼠标事件例子

wxpyhon 鼠标事件例子

#encoding:utf-8
import wx
import wx.aui
class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):

        wx.Frame.__init__(self, *args, **kwargs)
        self.mgr = wx.aui.AuiManager(self)

        leftpanel = wx.Panel(self, -1, size=(200, 150))
        rightpanel = wx.Panel(self, -1, size=(200, 150))
        bottompanel = wx.Panel(self, -1, size=(200, 150))
        bottompane2 = wx.Panel(self, -1, size=(200, 150))
        wangjiAN = wx.TextCtrl(rightpanel,style=wx.TE_RICH|wx.TE_AUTO_URL)
        btn = wx.Button(leftpanel)
        self.mgr.AddPane(bottompanel, wx.aui.AuiPaneInfo().Center().MaximizeButton(True).Layer(2))
        self.mgr.AddPane(leftpanel, wx.aui.AuiPaneInfo().Caption("hello2").Bottom().Layer(4))
        self.mgr.AddPane(rightpanel, wx.aui.AuiPaneInfo().Left().MaximizeButton(True).Layer(5))
        self.mgr.AddPane(bottompane2, wx.aui.AuiPaneInfo().Caption("hello1").Bottom().Layer(0))
        wangjiAN.Bind(wx.EVT_LEFT_DOWN, self.fun) #使用控件.Bind才能激活鼠标事件,self.Bind(wx.EVT,self.fun, wangjiAN)这个方法无法激活鼠标事件,谁响应鼠标事件谁bind
        wangjiAN.Bind(wx.EVT_LEFT_UP, self.fun)
        self.Bind(wx.EVT_BUTTON, self.fun)
        self.mgr.Update()
    def fun(self, event):
        print "**********************"

class MyApp(wx.App):
    def OnInit(self):

        frame = MyFrame(None, -1, ax.aui)
        frame.Show()
        self.SetTopWindow(frame)
        return 1

app = MyApp()
app.MainLoop()

EVT_LEFT_DOWN 鼠标左键按下。
EVT_LEFT_UP 鼠标左键抬起。
EVT_LEFT_DCLICK 鼠标左键双击

控件.Bind(WX.EVENT, FUN)

wxpyhon 鼠标事件例子