Search code examples
pythonimagemenuiconswxpython

Adding Icon or Image to wxpython GUI


I am trying to add icons to my menu options in wxpython. I have followed the code here but my image displays really large (not the nice icons size that Mike shows). Here is my code -- is there a way to make the icon fit the menu size (resize it)? Thanks!

self.HelpMenu = wx.Menu()

self.HelpAboutItem2 = wx.MenuItem(self.HelpMenu, 202, "&Visit Us", "Go to our website", wx.ITEM_NORMAL)
img = wx.Image('My_Image.jpg', wx.BITMAP_TYPE_ANY)
self.HelpAboutItem2.SetBitmap(wx.BitmapFromImage(img))
self.HelpMenu.AppendItem(self.HelpAboutItem2)

self.SetMenuBar(self.MainMenu)

Solution

  • I think I saved my image in a specific size for that particular example. I'm not finding anything in wx.Menu that let's you specify a size. However, wx.Image has Scale and Rescale methods that you might be able to use for scaling the image on the fly. I used that method in my image viewer tutorial to keep images from becoming too big for my screen.