wxPython menu doesn't display image

后端 未结 2 1945
小鲜肉
小鲜肉 2021-01-06 11:45

I am creating a menu and assigning images to menu items, sometime first item in menu doesn\'t display any image, I am not able to find the reason. I have tried to make a sim

相关标签:
2条回答
  • 2021-01-06 12:13

    This is a confirmed bug which appearently has been open for quite a while. After trying around a little bit, this workaround seems to do it:

        menuBar = wx.MenuBar()
        fileMenu=wx.Menu()
        tempitem = fileMenu.Append(-1,"X")       # !!!
        tempitem.SetBitmap(getBmp())             # !!!
        item = fileMenu.Append(wx.ID_NEW, "New")
        fileMenu.Remove(tempitem.GetId())        # !!!
        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) 
    

    Note that the position of the fileMenu.Remove call is the earliest position that works, but you can also move it to the bottom. HTH.

    0 讨论(0)
  • 2021-01-06 12:21

    This hack does not appear to be necessary if you create each menu item with wx.MenuItem(), set its bitmap, and only then append it to the menu. This causes the bitmaps to show up correctly. I'm testing with wxPython 2.8.10.1 on Windows.

    0 讨论(0)
提交回复
热议问题