メニューに画像を貼る練習
メニューバーのプルダウンメニューが文字だけでは味気ない場合があるので、メニューに画像を貼ってみる。wxPythonデモのessaimenu.pyに例があったのでその通りに。昔作ったコードを修正してやってみる。
以下、ソースコード。
import wx class MainFrame(wx.Frame): def __init__(self, id, title): width, height = 400, 250 wx.Frame.__init__(self, id, title="Quick File Selector", size=wx.Size(width, height)) mainPan = wx.Panel(self, -1) self.SetMenuBar(self.MakeMenu()) def MakeMenu(self): menu01 = wx.Menu() #simple menu menu01.Append(101, "&quit", "") # --- menu + picture item = wx.MenuItem(menu01, 101, "&quit") item.SetBitmap(wx.Bitmap('searchfile2.png')) menu01.AppendItem(item) # --- menuBar = wx.MenuBar() menuBar.Append(menu01, "Quit") wx.EVT_MENU(self, 101, self.QuitAppl) return menuBar def QuitAppl(self, event): pass class Application(wx.App): def OnInit(self): frame = MainFrame(None, -1) frame.Show(True) self.SetTopWindow(frame) return True def main(): app = Application(0) app.MainLoop() if __name__ == '__main__': main()