article

Friday, May 27, 2016

wxPython Icons and shortcuts Example

wxPython Icons and shortcuts Example
import wx

APP_EXIT = 1

class myframe(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, -1, title="Hello")
        self.InitUI()

    def InitUI(self):

        menubar = wx.MenuBar()
        fileMenu = wx.Menu()
        qmi = wx.MenuItem(fileMenu, 100, '&Quit\tCtrl+Q')
        qmi.SetBitmap(wx.Image('quit.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap()) #quit.png root folder
        fileMenu.AppendItem(qmi)

        self.Bind(wx.EVT_MENU, self.OnQuit, id=100)

        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)

        self.SetSize((250, 200))
        self.SetTitle('Icons and shortcuts')
        self.Centre()
        self.Show(True)

    def OnQuit(self, e):
        self.Close()

def main():
    ex = wx.App()
    ex.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
    myframe()
    ex.MainLoop()

if __name__ == '__main__':
    main()

Related Post