学习wxformbuilde
wxPython是Python的的GUI图形库,允许开发者很方便的创建GUI用户界面。 wxPython是作为优秀的跨平台开源GUI库wxWidgets(C++)的Python封装和Python模块的方式提供给用户的。
# -*- coding: utf-8 -*-
class MyFrame1 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer1 = wx.BoxSizer( wx.VERTICAL )
self.m_toolBar1 = wx.ToolBar( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TB_HORIZONTAL )
self.m_toolBar1.Realize()
bSizer1.Add( self.m_toolBar1, 0, wx.EXPAND, 5 )
self.SetSizer( bSizer1 )
self.Layout()
self.m_statusBar1 = self.CreateStatusBar( 1, wx.ST_SIZEGRIP, wx.ID_ANY )
self.m_menubar1 = wx.MenuBar( 0 )
self.m_menu2 = wx.Menu()
self.m_menu21 = wx.Menu()
self.m_menu2.AppendSubMenu( self.m_menu21, u"MyMenu" )
self.m_menubar1.Append( self.m_menu2, u"MyMenu" )
self.m_menu6 = wx.Menu()
self.m_menu31 = wx.Menu()
self.m_menu41 = wx.Menu()
self.m_menu31.AppendSubMenu( self.m_menu41, u"MyMenu" )
self.m_menu6.AppendSubMenu( self.m_menu31, u"MyMenu" )
self.m_menubar1.Append( self.m_menu6, u"MyMenu" )
self.m_menu3 = wx.Menu()
self.m_menu51 = wx.Menu()
self.m_menu3.AppendSubMenu( self.m_menu51, u"MyMenu" )
self.m_menubar1.Append( self.m_menu3, u"MyMenu" )
self.m_menu4 = wx.Menu()
self.m_menu61 = wx.Menu()
self.m_menu4.AppendSubMenu( self.m_menu61, u"MyMenu" )
self.m_menubar1.Append( self.m_menu4, u"MyMenu" )
self.m_menu5 = wx.Menu()
self.m_menubar1.Append( self.m_menu5, u"MyMenu" )
self.SetMenuBar( self.m_menubar1 )
self.Centre( wx.BOTH )
def __del__( self ):
pass
事件分发
import wx
class MyPanel(wx.Panel):
def __init__(self, parent):
super(MyPanel, self).__init__(parent)
b = wx.Button(self, label = 'Btn', pos = (100,100))
b.Bind(wx.EVT_BUTTON, self.btnclk)
self.Bind(wx.EVT_BUTTON, self.OnButtonClicked)
def OnButtonClicked(self, e):
print 'Panel 收到点击事件. 分发给 Frame class'
e.Skip()
def btnclk(self,e):
print "Button 收到点击事件. 分发给 Panel class"
e.Skip()
class Example(wx.Frame):
def __init__(self,parent):
super(Example, self).__init__(parent)
self.InitUI()
def InitUI(self):
mpnl = MyPanel(self)
self.Bind(wx.EVT_BUTTON, self.OnButtonClicked)
self.SetTitle('事件分发')
self.Centre()
self.Show(True)
def OnButtonClicked(self, e):
print 'frame class 收到点击事件'
e.Skip()
ex = wx.App()
Example(None)
ex.MainLoop()
参考网址:
http://blog.topspeedsnail.com/archives/1190
https://www.cnblogs.com/henjay724/p/9426966.html