最近没有时间学Python了,上个星期打算使用Python开发一个小应用,没想到使用tkinter开发MDI窗口应用很费劲,转到wxPython后发现可以参考的资料不多,不过在CSDN上还是有,折腾了一阵子,完成了一个框架,记录下来完善。
import wx
#MDI窗体框架
SAppName="生产设备信息管理"
APP_ICON = 'G:\Python\demo\demo\PIC\yqcyxxda.ico'
class MDIFrame(wx.MDIParentFrame):
def __init__(self):
wx.MDIParentFrame.__init__(self, None, -1, SAppName ,size=(800,600))
# wx.MDIParentFrame.__init__(self, None, -1, SAppName, size=(800, 600),style=wx.DEFAULT_FRAME_STYLE ^ (wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX)) # 去除最大化和最小化窗口
MainMenu1 = wx.Menu()
MM1Child1 = MainMenu1.Append(wx.ID_FILE1, "主设备台帐", "主设备台帐")
MM1Child2 = MainMenu1.Append(wx.ID_FILE2, "辅助设备台帐", "辅助设备台帐")
MainMenu1.AppendSeparator()
self.Bind(wx.EVT_MENU, self.MyFunction1, MM1Child1)
self.Bind(wx.EVT_MENU, self.MyFunction2, MM1Child2)
ChildMenu1 = wx.Menu()
MM1Child41=ChildMenu1.Append(wx.ID_ANY,"主设备参数")
MM1Child42=ChildMenu1.Append(wx.ID_ANY,"辅助设备参数")
# MainMenu1.AppendMenu(wx.ID_ANY, "设备参数设置", ChildMenu1)
MainMenu1.Append(wx.ID_ANY, "设备参数设置", ChildMenu1)
self.Bind(wx.EVT_MENU, self.MyFunction4, MM1Child41)
self.Bind(wx.EVT_MENU, self.MyFunction5, MM1Child42)
menuBar = wx.MenuBar()
menuBar.Append(MainMenu1, "台帐")
self.SetMenuBar(menuBar)
MainMenu2 = wx.Menu()
MM2Child1 = MainMenu2.Append(wx.ID_FILE1, "招投标", "招投标")
self.Bind(wx.EVT_MENU, self.MyFunction3, MM2Child1)
menuBar.Append(MainMenu2, "招标和投标文件")
self.SetMenuBar(menuBar)
icon = wx.Icon(APP_ICON, wx.BITMAP_TYPE_ICO)
self.SetIcon(icon)
self._CreateStatusBar() # 创建状态栏
self.SetSize((800, 600)) # 重新设置大小尺寸
self.SetTitle(SAppName) # 重新设置应用名称
self.Center() # 窗口居中
self.Show()
def _CreateStatusBar(self):
# 创建状态栏
self.sb = self.CreateStatusBar()
self.sb.SetFieldsCount(3)
self.sb.SetStatusWidths([-2, -1, -1])
self.sb.SetStatusStyles([wx.SB_RAISED, wx.SB_RAISED, wx.SB_RAISED])
self.sb.SetStatusText(u'状态信息0', 0)
self.sb.SetStatusText(u'', 1)
self.sb.SetStatusText(u'状态信息2', 2)
def MyFunction1(self, e):
win=wx.MDIChildFrame(self, -1, "主设备台帐")
# self.Center()
win.Show(True)
def MyFunction2(self, e):
win=wx.MDIChildFrame(self, -1, "辅助设备台帐")
win.Show(True)
def MyFunction3(self, e):
win=wx.MDIChildFrame(self, -1, "招标和投标文件")
win.Show(True)
def MyFunction4(self, e):
win = wx.MDIChildFrame(self, -1, "主设备参数")
win.Show(True)
def MyFunction5(self, e):
win = wx.MDIChildFrame(self, -1, "辅助设备参数")
win.Show(True)
if __name__ == '__main__':
# app = wx.PySimpleApp()
app = wx.App()
frame = MDIFrame()
frame.Show()
app.MainLoop() 界面如下: