wxpython入门

简介

wxPythonPython语言的一套优秀的GUI图形库。允许Python程序员很方便的创建完整的、功能键全的GUI用户界面。 wxPython是作为优秀的跨平台GUIwxWidgetsPython封装和Python模块的方式提供给用户的。

使用wxPython创建GUI需要以下五个步骤:

  1. 导入必须的wxPython
  2. 子类化wxPython应用程序类
  3. 定义一个应用程序的初始化方法
  4. 创建一个应用程序类的实例
  5. 进入这个应用程序的主事件循环
import wx #1
class App(wx.App): #2
    def OnInit(self): #3
        frame = wx.Frame(parent=None, title="Tool")
        frame.Show()
        return True
app = App() #4
app.MainLoop() #5
输出.png

菜单栏

创建菜单栏需要五个步骤:

  1. 创建菜单menufile = wx.Menu()
  2. 创建子菜单,并添加快捷键exit_item = menufile.Append(wx.ID_EXIT, u"&退出\tCtrl+E")
  3. 创建菜单栏,添加快捷键
menubar = wx.MenuBar()
menubar.Append(menufile, u" 文件(&F)") # Alt+F
  1. 添加响应self.Bind(wx.EVT_MENU, self.handle_exit, exit_item)
  2. 设置菜单栏self.SetMenuBar(menubar)
#!/usr/bin/env python
#-*-coding:utf-8-*-

import wx

class MainFrame(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, None, title=u"B-BOX", size=(400, 300))
        self.height = self.GetClientSize().GetHeight()
        self.width = self.GetClientSize().GetWidth()
        self.Centre()
        self.menu_layout()

    def menu_layout(self):
        #################################################### 菜单布局
        menufile = wx.Menu()
        exit_item = menufile.Append(wx.ID_EXIT, u"&退出\tCtrl+E")
        self.Bind(wx.EVT_MENU, self.handle_exit, exit_item)

        helpfile = wx.Menu()
        manual_item = helpfile.Append(-1, u"&关于")
        helpfile.AppendSeparator()
        about_item = helpfile.Append(-1, u"&帮助文档")

        editfile = wx.Menu()
        copy_item = editfile.Append(-1, u"&路径配置\tCtrl+S")

        platfile = wx.Menu()
        self.bbox_menu = platfile.AppendRadioItem(-1, u"B-BOX\tCtrl+B")
        self.view_bin_menu = platfile.AppendRadioItem(-1, u"ViewBin\tCtrl+V")

        menubar = wx.MenuBar()
        menubar.Append(menufile, u" 文件(&F)")
        menubar.Append(platfile, u" 模式(&M)")
        menubar.Append(editfile, u" 设置(&S)")
        menubar.Append(helpfile, u" 帮助(&H)")
        self.SetMenuBar(menubar)
    
    def handle_exit(self, evt):
        dlg = wx.MessageDialog(None,u'确定关闭当前窗口?', u'提示',wx.ICON_INFORMATION | wx.YES_NO | wx.STAY_ON_TOP | wx.YES_DEFAULT)
        if dlg.ShowModal() == wx.ID_YES:
            self.Destroy()
        dlg.Destroy()

class MyApp(wx.App):
    def OnInit(self):
        frame = MainFrame(None, -1)
        frame.Show(True)
        return True

if __name__ == '__main__':
    app = MyApp(redirect=False)
    app.MainLoop()
菜单栏实现.png

工具栏

创建带图标的按钮栏流程:

  1. 使用wx库图标self.home= wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR),自定义图标自行百度;
  2. 创建工具栏self.toolbar = wx.ToolBar(self,-1,style=wx.TB_HORZ_TEXT,name="toolBar")
  3. 在工具栏上添加按钮self.home_tool = self.toolbar.AddTool(-1,u"基本信息",self.home,shortHelp = u"基本信息")
  4. 添加响应函数;
  5. 设置工具栏;
self.SetSizer(sizer)
self.toolbar.Realize()
def tool_layout(self):
    #################################################### 工具栏
    self.toolbar = wx.ToolBar(self,-1,style=wx.TB_HORZ_TEXT,name="toolBar") #|wx.TB_NOICONS

    self.home= wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR)
    self.list_bmp= wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR)
    self.error= wx.ArtProvider.GetBitmap(wx.ART_CROSS_MARK, wx.ART_TOOLBAR)
    self.report_bmp= wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_TOOLBAR)
    self.exec_bmp= wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_TOOLBAR)
    self.find_bmp= wx.ArtProvider.GetBitmap(wx.ART_HELP_SIDE_PANEL, wx.ART_TOOLBAR)

    self.home_tool = self.toolbar.AddTool(-1,u"基本信息",self.home,shortHelp = u"基本信息")
    self.stack_tool = self.toolbar.AddTool(-1,u"栈信息",self.list_bmp,shortHelp = u"栈信息")
    self.error_code_tool = self.toolbar.AddTool(-1,u"错误信息",self.error,shortHelp = u"错误信息")
    self.status_tool = self.toolbar.AddTool(-1,u"状态寄存器",self.report_bmp,shortHelp = u"状态寄存器")
    self.maple_tool = self.toolbar.AddTool(-1,u"maple寄存器",self.exec_bmp,shortHelp = u"maple寄存器")
    self.si_tool = self.toolbar.AddTool(-1,u"系统信息",self.find_bmp,shortHelp = u"系统信息")

    sizer = wx.FlexGridSizer(0,1,0,0)

    sizer.Add(self.toolbar, 1, wx.ALIGN_TOP | wx.EXPAND)
    sizer.Add(wx.StaticLine(self), 1, wx.EXPAND)

    self.panel = wx.Panel(self,size=(self.width,self.height))
    self.nb = wx.aui.AuiNotebook(self.panel,pos=(0,0),size=(self.width,self.height),style=wx.aui.AUI_NB_DEFAULT_STYLE)

    sizer.Add(self.panel, 1, wx.ALIGN_LEFT | wx.EXPAND)
    self.SetSizer(sizer)
    self.toolbar.Realize()
按钮栏.png

状态栏

状态栏添加分以下几个步骤:

  1. 创建状态栏self.statusbar = self.CreateStatusBar()
  2. 状态栏分块,划分块比例
self.statusbar.SetFieldsCount(3)
self.statusbar.SetStatusWidths([-1,-2,-2])
  1. 添加状态栏内容
self.statusbar.SetStatusText(u"     模式 : B-BOX",0)
self.statusbar.SetStatusText(u"     版本信息 : eNB_V16A.016.1",1)
self.statusbar.SetStatusText(u"     编译时间 : 17:41:09 Dec 17 2016",2)

代码如下:

def status_layout(self):
    self.statusbar = self.CreateStatusBar()
    self.statusbar.SetFieldsCount(3)
    self.statusbar.SetStatusWidths([-1,-2,-2])
    self.statusbar.SetStatusText(u"     模式 : B-BOX",0)
    self.statusbar.SetStatusText(u"     版本信息 : eNB_V16A.016.1",1)
    self.statusbar.SetStatusText(u"     编译时间 : 17:41:09 Dec 17 2016",2)
状态栏.png

页面

添加页面步骤:

  1. 绑定事件self.Bind(wx.EVT_MENU,self.home_platform,self.home_tool)
  2. 新页面显示;
    def home_platform(self,evt):
        self.home_page = homePage(self.nb,self.width,self.height)
        self.nb.AddPage(self.home_page,u"基本信息")


class homePage(wx.Panel):
    def __init__(self,parent,width,height):
        wx.Panel.__init__(self,parent)
        self.height = height
        self.width = width
页面显示.png

控件添加

静态文本控件、文本框控件、表格控件

def display(self):
    self.sizer_bar = wx.BoxSizer(wx.VERTICAL)
    crash = wx.StaticText(self, -1, label=u"Crash 信息")
    self.t_crash = wx.TextCtrl(self,-1, size=self.size, style=wx.TE_MULTILINE)
    general = wx.StaticText(self, -1, label=u"general register")
    self.t_general = wx.TextCtrl(self,-1, size=self.size, style=wx.TE_MULTILINE)
    sys_status = wx.StaticText(self, -1, label=u"sys_status")
    self.t_sys_status = grid.Grid(self,size=self.size_1)
    self.t_sys_status.CreateGrid(10,3)
    ramlog = wx.StaticText(self, -1, label=u"ramlog")
    self.t_ramlog = wx.TextCtrl(self,-1, size=self.size_1, style=wx.TE_MULTILINE)

    sizer0 = wx.FlexGridSizer(0,2,5,5)
    sizer0.Add(crash, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5)
    sizer0.Add(general, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5)
    sizer0.Add(self.t_crash, 1, wx.ALIGN_CENTER | wx.ALL, border=10)
    sizer0.Add(self.t_general, 1, wx.ALIGN_CENTER | wx.ALL, border=10)
    sizer0_ = wx.StaticBoxSizer(wx.StaticBox(self, -1, u''), wx.VERTICAL)
    sizer0_.Add(sizer0, wx.ALIGN_CENTER | wx.ALL, border=5)

    sizer1 = wx.FlexGridSizer(0,2,5,5)
    sizer1.Add(sys_status, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5)
    sizer1.Add(ramlog, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5)
    sizer1.Add(self.t_sys_status, 1, wx.ALIGN_CENTER | wx.ALL, border=10)
    sizer1.Add(self.t_ramlog, 1, wx.ALIGN_CENTER | wx.ALL, border=10)
    sizer1_ = wx.StaticBoxSizer(wx.StaticBox(self, -1, u''), wx.VERTICAL)
    sizer1_.Add(sizer1, wx.ALIGN_CENTER | wx.ALL, border=5)


    sizer_panel = wx.FlexGridSizer(0,2,10,10)
    sizer_panel.Add(wx.StaticText(self, -1, size=(10,0),label=""))
    sizer_panel.Add(sizer0_, wx.ALIGN_LEFT | wx.ALL, border=20)
    sizer_panel.Add(wx.StaticText(self, -1, size=(10,0),label=""))
    sizer_panel.Add(sizer1_, wx.ALIGN_LEFT | wx.ALL, border=20)

    self.sizer_bar.Add(sizer_panel, wx.ALIGN_LEFT | wx.ALL, border=20)
    self.sizer_bar.Layout()
    self.SetSizer(self.sizer_bar)
    self.t_crash.Clear()
静态文本、多行文本框、表格.png

树形控件、按钮控件

class statusPage(wx.Panel):
    def __init__(self,parent,width,height):
        wx.Panel.__init__(self,parent)
        self.height = height
        self.width = width
        self.display()

    def display(self):
        self.toolbar = wx.ToolBar(self,-1,style=wx.TB_HORZ_TEXT,pos=(0,0),name="toolBar") #|wx.TB_NOICONS
        CoreId = wx.StaticText(self.toolbar,label=u"  选择核:")
        
        t_CoreId = wx.ComboBox(self.toolbar,choices=["Cell0","Cell1","Cell2"])

        t_CoreId.SetSelection(0)
        self.toolbar.AddControl(CoreId)
        self.toolbar.AddControl(t_CoreId)
        self.toolbar.AddSeparator()
        self.toolbar.AddSeparator()
        self.expand_bmp= wx.ArtProvider.GetBitmap(wx.ART_ADD_BOOKMARK, wx.ART_TOOLBAR)
        self.collapse_bmp= wx.ArtProvider.GetBitmap(wx.ART_DEL_BOOKMARK, wx.ART_TOOLBAR)
        expand_tool = self.toolbar.AddTool(wx.ID_ANY,u"展开",self.expand_bmp,shortHelp = u"展开树形控件")
        collapse_tool = self.toolbar.AddTool(wx.ID_ANY,u"折叠",self.collapse_bmp,shortHelp = u"折叠树形控件")
        self.Bind(wx.EVT_MENU,self.expand,expand_tool)
        self.Bind(wx.EVT_MENU,self.collapse,collapse_tool)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.toolbar, 1, wx.EXPAND | wx.BOTTOM, 0)
        tree_style = wx.TR_DEFAULT_STYLE | wx.TR_SINGLE | wx.TR_HAS_BUTTONS | wx.TR_EDIT_LABELS
        self.tree = wx.TreeCtrl(self, style=tree_style, pos = (100,36),size = (self.width,self.height-94))
        self.root = self.tree.AddRoot(u"Stat",image = wx.TreeItemIcon_Normal)
        sizer.Add(self.tree, 1, wx.EXPAND | wx.BOTTOM, 0)
        node_1 = self.tree.AppendItem(self.root, "a = 1")
        node_2 = self.tree.AppendItem(self.root, "b = 2")
        node_3 = self.tree.AppendItem(self.root, "c = 3")
        node_4 = self.tree.AppendItem(node_3, "d = 4")
        node_5 = self.tree.AppendItem(node_3, "e = 5")
        self.SetSizer(sizer)
        self.toolbar.Realize()

    def expand(self,evt):
        self.tree.ExpandAll()

    def collapse(self,evt):
        self.tree.CollapseAll()
树形控件、按钮控件.png

嵌入Matplotlib绘图

class sinPage(wx.Panel):
    def __init__(self,parent,width,height):
        wx.Panel.__init__(self,parent)
        self.Figure = matplotlib.figure.Figure(figsize=(8,6),dpi=80)
        self.axes = self.Figure.add_axes([0.1,0.1,0.8,0.8])
        self.axes.grid()
        self.FigureCanvas = FigureCanvas(self,-1,self.Figure)
        self.sin()

    def sin(self):
        x = np.linspace(0, 10, 500)
        y = np.sin(x)
        line1 = self.axes.plot(x, y, label='Using set_dashes()')
        self.axes.legend()
        self.FigureCanvas.draw()
嵌入matplotlib图像.png

打包

打包需要安装python第三方库pyinstaller
安装方法

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller

pyinstaller命令行选项

选项 说明
-F,-onefile 产生单个的可执行文件
-D,--onedir 产生一个目录(包含多个文件)作为可执行程序
-w,--windowed,--noconsolc 指定程序运行时不显示命令行窗口(仅对 Windows 有效)
-c,--nowindowed,--console 指定使用命令行窗口运行程序(仅对 Windows 有效)
--icon 指定应用程序图标
-n NAME,--name=NAME 指定应用程序名

因此,建议的打包方法如下:

pyinstaller -F -w main.py --icon=.\icon.ico -n main

PS:不建议使用numpymatplotlibscipy的库打包,产生的可执行文件非常大。

参考文档:https://docs.wxpython.org/index.html
全部源码如下:

#!/usr/bin/env python
#-*-coding:utf-8-*-

import wx
import wx.aui
from wx import grid
import numpy as np
import matplotlib
# matplotlib采用WXAgg为后台,将matplotlib嵌入wxPython中
matplotlib.use("WXAgg")
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

class MainFrame(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, None, title=u"B-BOX", size=(650, 600))
        self.height = self.GetClientSize().GetHeight()
        self.width = self.GetClientSize().GetWidth()
        self.Centre()
        self.menu_layout()
        self.tool_layout()
        self.status_layout()

    def menu_layout(self):
        #################################################### 菜单布局
        menufile = wx.Menu()
        exit_item = menufile.Append(wx.ID_EXIT, u"&退出\tCtrl+E")
        self.Bind(wx.EVT_MENU, self.handle_exit, exit_item)

        helpfile = wx.Menu()
        manual_item = helpfile.Append(-1, u"&关于")
        helpfile.AppendSeparator()
        about_item = helpfile.Append(-1, u"&帮助文档")

        editfile = wx.Menu()
        copy_item = editfile.Append(-1, u"&路径配置\tCtrl+S")

        platfile = wx.Menu()
        self.bbox_menu = platfile.AppendRadioItem(-1, u"B-BOX\tCtrl+B")
        self.view_bin_menu = platfile.AppendRadioItem(-1, u"ViewBin\tCtrl+V")

        menubar = wx.MenuBar()
        menubar.Append(menufile, u" 文件(&F)")
        menubar.Append(platfile, u" 模式(&M)")
        menubar.Append(editfile, u" 设置(&S)")
        menubar.Append(helpfile, u" 帮助(&H)")
        self.SetMenuBar(menubar)

    def tool_layout(self):
        #################################################### 工具栏
        self.toolbar = wx.ToolBar(self,-1,style=wx.TB_HORZ_TEXT,name="toolBar") #|wx.TB_NOICONS

        self.home= wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR)
        self.list_bmp= wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR)
        self.error= wx.ArtProvider.GetBitmap(wx.ART_CROSS_MARK, wx.ART_TOOLBAR)
        self.report_bmp= wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_TOOLBAR)
        self.exec_bmp= wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_TOOLBAR)
        self.find_bmp= wx.ArtProvider.GetBitmap(wx.ART_HELP_SIDE_PANEL, wx.ART_TOOLBAR)

        self.home_tool = self.toolbar.AddTool(-1,u"基本信息",self.home,shortHelp = u"基本信息")
        self.stack_tool = self.toolbar.AddTool(-1,u"栈信息",self.list_bmp,shortHelp = u"栈信息")
        self.error_code_tool = self.toolbar.AddTool(-1,u"错误信息",self.error,shortHelp = u"错误信息")
        self.status_tool = self.toolbar.AddTool(-1,u"状态寄存器",self.report_bmp,shortHelp = u"状态寄存器")
        self.maple_tool = self.toolbar.AddTool(-1,u"maple寄存器",self.exec_bmp,shortHelp = u"maple寄存器")
        self.sin_tool = self.toolbar.AddTool(-1,u"sin函数",self.find_bmp,shortHelp = u"sin函数")

        self.Bind(wx.EVT_MENU,self.home_platform,self.home_tool)
        self.Bind(wx.EVT_MENU,self.status_platform,self.status_tool)
        self.Bind(wx.EVT_MENU,self.sin_platform,self.sin_tool)

        sizer = wx.FlexGridSizer(0,1,0,0)

        sizer.Add(self.toolbar, 1, wx.ALIGN_TOP | wx.EXPAND)
        sizer.Add(wx.StaticLine(self), 1, wx.EXPAND)

        self.panel = wx.Panel(self,size=(self.width,self.height))
        self.nb = wx.aui.AuiNotebook(self.panel,pos=(0,0),size=(self.width,self.height),style=wx.aui.AUI_NB_DEFAULT_STYLE)

        sizer.Add(self.panel, 1, wx.ALIGN_LEFT | wx.EXPAND)
        self.SetSizer(sizer)
        self.toolbar.Realize()

    def status_layout(self):
        self.statusbar = self.CreateStatusBar()
        self.statusbar.SetFieldsCount(3)
        self.statusbar.SetStatusWidths([-1,-2,-2])
        self.statusbar.SetStatusText(u"     模式 : B-BOX",0)
        self.statusbar.SetStatusText(u"     版本信息 : eNB_V16A.016.1",1)
        self.statusbar.SetStatusText(u"     编译时间 : 17:41:09 Dec 17 2016",2)
    
    def handle_exit(self, evt):
        dlg = wx.MessageDialog(None,u'确定关闭当前窗口?', u'提示',wx.ICON_INFORMATION | wx.YES_NO | wx.STAY_ON_TOP | wx.YES_DEFAULT)
        if dlg.ShowModal() == wx.ID_YES:
            self.Destroy()
        dlg.Destroy()

    def sin_platform(self,evt):
        self.sin_page = sinPage(self.nb,self.width,self.height)
        self.nb.AddPage(self.sin_page,u"sin函数")

    def home_platform(self,evt):
        self.home_page = homePage(self.nb,self.width,self.height)
        self.nb.AddPage(self.home_page,u"基本信息")

    def status_platform(self,evt):
        self.status_page = statusPage(self.nb,self.width,self.height)
        self.nb.AddPage(self.status_page,u"状态寄存器")

class sinPage(wx.Panel):
    def __init__(self,parent,width,height):
        wx.Panel.__init__(self,parent)
        self.Figure = matplotlib.figure.Figure(figsize=(8,6),dpi=80)
        self.axes = self.Figure.add_axes([0.1,0.1,0.8,0.8])
        self.axes.grid()
        self.FigureCanvas = FigureCanvas(self,-1,self.Figure)
        self.sin()

    def sin(self):
        x = np.linspace(0, 10, 500)
        y = np.sin(x)
        line1 = self.axes.plot(x, y, label='Using set_dashes()')
        self.axes.legend()
        self.FigureCanvas.draw()

class statusPage(wx.Panel):
    def __init__(self,parent,width,height):
        wx.Panel.__init__(self,parent)
        self.height = height
        self.width = width
        self.display()

    def display(self):
        self.toolbar = wx.ToolBar(self,-1,style=wx.TB_HORZ_TEXT,pos=(0,0),name="toolBar") #|wx.TB_NOICONS
        CoreId = wx.StaticText(self.toolbar,label=u"  选择核:")
        
        t_CoreId = wx.ComboBox(self.toolbar,choices=["Cell0","Cell1","Cell2"])

        t_CoreId.SetSelection(0)
        self.toolbar.AddControl(CoreId)
        self.toolbar.AddControl(t_CoreId)
        self.toolbar.AddSeparator()
        self.toolbar.AddSeparator()
        self.expand_bmp= wx.ArtProvider.GetBitmap(wx.ART_ADD_BOOKMARK, wx.ART_TOOLBAR)
        self.collapse_bmp= wx.ArtProvider.GetBitmap(wx.ART_DEL_BOOKMARK, wx.ART_TOOLBAR)
        expand_tool = self.toolbar.AddTool(wx.ID_ANY,u"展开",self.expand_bmp,shortHelp = u"展开树形控件")
        collapse_tool = self.toolbar.AddTool(wx.ID_ANY,u"折叠",self.collapse_bmp,shortHelp = u"折叠树形控件")
        self.Bind(wx.EVT_MENU,self.expand,expand_tool)
        self.Bind(wx.EVT_MENU,self.collapse,collapse_tool)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.toolbar, 1, wx.EXPAND | wx.BOTTOM, 0)
        tree_style = wx.TR_DEFAULT_STYLE | wx.TR_SINGLE | wx.TR_HAS_BUTTONS | wx.TR_EDIT_LABELS
        self.tree = wx.TreeCtrl(self, style=tree_style, pos = (100,36),size = (self.width,self.height-94))
        self.root = self.tree.AddRoot(u"Stat",image = wx.TreeItemIcon_Normal)
        sizer.Add(self.tree, 1, wx.EXPAND | wx.BOTTOM, 0)
        node_1 = self.tree.AppendItem(self.root, "a = 1")
        node_2 = self.tree.AppendItem(self.root, "b = 2")
        node_3 = self.tree.AppendItem(self.root, "c = 3")
        node_4 = self.tree.AppendItem(node_3, "d = 4")
        node_5 = self.tree.AppendItem(node_3, "e = 5")
        self.SetSizer(sizer)
        self.toolbar.Realize()

    def expand(self,evt):
        self.tree.ExpandAll()

    def collapse(self,evt):
        self.tree.CollapseAll()

class homePage(wx.Panel):
    def __init__(self,parent,width,height):
        wx.Panel.__init__(self,parent)
        self.height = height
        self.width = width
        self.size = ((self.width-100)/2,(self.height-300)/2)
        self.size_1 = ((self.width-100)/2,(self.height-300)/2+30)
        self.display()

    def display(self):
        self.sizer_bar = wx.BoxSizer(wx.VERTICAL)
        crash = wx.StaticText(self, -1, label=u"Crash 信息")
        self.t_crash = wx.TextCtrl(self,-1, size=self.size, style=wx.TE_MULTILINE)
        general = wx.StaticText(self, -1, label=u"general register")
        self.t_general = wx.TextCtrl(self,-1, size=self.size, style=wx.TE_MULTILINE)
        sys_status = wx.StaticText(self, -1, label=u"sys_status")
        # self.t_sys_status = wx.TextCtrl(self,-1, size=self.size, style=wx.TE_MULTILINE)
        self.t_sys_status = grid.Grid(self,size=self.size_1)
        self.t_sys_status.CreateGrid(10,3)
        ramlog = wx.StaticText(self, -1, label=u"ramlog")
        self.t_ramlog = wx.TextCtrl(self,-1, size=self.size_1, style=wx.TE_MULTILINE)

        sizer0 = wx.FlexGridSizer(0,2,5,5)
        sizer0.Add(crash, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5)
        sizer0.Add(general, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5)
        sizer0.Add(self.t_crash, 1, wx.ALIGN_CENTER | wx.ALL, border=10)
        sizer0.Add(self.t_general, 1, wx.ALIGN_CENTER | wx.ALL, border=10)
        sizer0_ = wx.StaticBoxSizer(wx.StaticBox(self, -1, u''), wx.VERTICAL)
        sizer0_.Add(sizer0, wx.ALIGN_CENTER | wx.ALL, border=5)

        sizer1 = wx.FlexGridSizer(0,2,5,5)
        sizer1.Add(sys_status, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5)
        sizer1.Add(ramlog, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=5)
        sizer1.Add(self.t_sys_status, 1, wx.ALIGN_CENTER | wx.ALL, border=10)
        sizer1.Add(self.t_ramlog, 1, wx.ALIGN_CENTER | wx.ALL, border=10)
        sizer1_ = wx.StaticBoxSizer(wx.StaticBox(self, -1, u''), wx.VERTICAL)
        sizer1_.Add(sizer1, wx.ALIGN_CENTER | wx.ALL, border=5)


        sizer_panel = wx.FlexGridSizer(0,2,10,10)
        sizer_panel.Add(wx.StaticText(self, -1, size=(10,0),label=""))
        sizer_panel.Add(sizer0_, wx.ALIGN_LEFT | wx.ALL, border=20)
        sizer_panel.Add(wx.StaticText(self, -1, size=(10,0),label=""))
        sizer_panel.Add(sizer1_, wx.ALIGN_LEFT | wx.ALL, border=20)

        self.sizer_bar.Add(sizer_panel, wx.ALIGN_LEFT | wx.ALL, border=20)
        self.sizer_bar.Layout()
        self.SetSizer(self.sizer_bar)
        self.t_crash.Clear()

class MyApp(wx.App):
    def OnInit(self):
        frame = MainFrame(None, -1)
        frame.Show(True)
        return True

if __name__ == '__main__':
    app = MyApp(redirect=False)
    app.MainLoop()

你可能感兴趣的:(wxpython入门)