wxPython menu doesn't display image

后端 未结 2 1946
小鲜肉
小鲜肉 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.

提交回复
热议问题