Pythonエクスペリエンス(08)-グラフィックインタフェースのツールバーとステータスバー

5297 ワード

# 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()  #