I borrowed an example code from here and altered it for my purpose:

import wx

def getBmp():
    bmp = wx.EmptyBitmapRGBA(16,16, red=100, green=50, blue=50)
    return bmp

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, style=wx.DEFAULT_FRAME_STYLE, parent=None)

        self.SetTitle("why No image?")

        menuBar = wx.MenuBar()
        fileMenu = wx.Menu()
        item = fileMenu.Append(wx.ID_NEW, "New")
        item.SetBitmap(getBmp())
        item = fileMenu.Append(wx.ID_OPEN, "Open")
        item.SetBitmap(getBmp())
        item = fileMenu.Append(wx.ID_SAVE, "Save")
        item.SetBitmap(getBmp())
        menuBar.Append(fileMenu, "File")
        self.SetMenuBar(menuBar)

app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.SetTopWindow(frame)
app.MainLoop()

Problem: On my system configuration (Ubuntu 12.04 and wxPython 2.8.12.1) there is no icon/bitmap being displayed for any of the menu entries. No error messages except when I close down the window:

*(python:3321): LIBDBUSMENU-GLIB-WARNING ***: Trying to remove a child that doesn't believe we're it's parent.

有帮助吗?

解决方案

It sounds like Unity takes all menubars and puts them in the Global menu - http://ubuntuforums.org/showthread.php?t=2004101

These two links discuss the issue a bit more:

The last one has a solution for removing the menubars in such a way that you won't see the error anymore, but it doesn't sound like it works in a cross-platform manner.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top