许明会的计算机技术主页

Language:C,C++,.NET Framework(C#)
Thinking:Design Pattern,Algorithm,WPF,Windows Internals
Database:SQLServer,Oracle,MySQL,PostSQL
IT:MCITP,Exchange,Lync,Virtualization,CCNP

导航

Python体验(08)-图形界面之工具栏和状态栏

 

# coding=utf-8
import wx  # 导入必须的Python包

class MenuForm(wx.Frame):
    def OnQuit(self,event):
        self.Close()
    def OnOpen(self,event):
        self.statusbar.SetStatusText('Open a File!')

    def __init__(self,parent,ID,title):
        wx.Frame.__init__(self,parent,ID,title)
        #mnuFile
        mnuFile=wx.Menu()
        mnuFile.Append(100,'&Open\tCtrl+O','Open File')
        mnuFile.AppendSeparator()
        mnuFile.Append(105,'&Quit\tCtrl+Q','Quit Application')
        #EVT_MENU
        wx.EVT_MENU(self,105,self.OnQuit)
        #menuBar
        menuBar = wx.MenuBar()
        menuBar.Append(mnuFile,"&File")
        self.SetMenuBar(menuBar)
        self.Centre()
        #ToolBar StatusBar
        vbox=wx.BoxSizer(wx.VERTICAL)
        toolBar=wx.ToolBar(self,-1,style=wx.TB_HORIZONTAL|wx.NO_BORDER)
        toolBar.AddSimpleTool(1,wx.Image('stock_Open.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap(),'Open','')
        toolBar.AddSeparator()
        toolBar.AddSimpleTool(3,wx.Image('stock_exit.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap(),'Exit','')
        toolBar.Realize()
        vbox.Add(toolBar,0,border=5)
        self.SetSizer(vbox)
        self.statusbar = self.CreateStatusBar()
        #EVT_TOOL
        wx.EVT_TOOL(self,1,self.OnOpen)
        wx.EVT_TOOL(self,3,self.OnQuit)

class App(wx.App):  # 子类化wxPython应用程序类
    def OnInit(self):  # 定义一个应用程序的初始化方法
        frame = MenuForm(parent=None,ID=-1,title="GUI with Menu")
        frame.Show(True)
        return True

app = App()  # 创建一个应用程序类的实例
app.MainLoop()  # 进入这个应用程序的主事件循环

 

posted on 2016-03-20 22:35  许明会  阅读(2127)  评论(0编辑  收藏  举报