📌  相关文章
📜  wxPython – wx.MenuBar 中的 GetMenus()函数

📅  最后修改于: 2022-05-13 01:55:31.966000             🧑  作者: Mango

wxPython – wx.MenuBar 中的 GetMenus()函数

在本文中,我们将学习与 wxPython 的 wx.MenuBar 类关联的 GetMenus()函数。 GetMenus()函数只返回 MenuBar 中菜单的 (menu, label) 项列表。
GetMenus()函数中不需要任何参数。

代码示例:

import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
  
        self.InitUI()
  
    def InitUI(self):
  
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        self.menubar = wx.MenuBar()
        self.fileMenu = wx.Menu()
        self.fileMenu2 = wx.Menu()
        self.item = wx.MenuItem(self.fileMenu, 1, '&Check', 
                                 helpString ="Check Help")
        self.item.SetBitmap(wx.Bitmap('right.png'))
        self.fileMenu.Append(self.item)
        self.menubar.Append(self.fileMenu, '&File')
        self.menubar.Append(self.fileMenu2, '&Info')
        self.SetMenuBar(self.menubar)
  
        # PRINT (MENU, LABEL) LIST ITEMS IN MENUBAR
        print(self.menubar.GetMenus())
        self.SetSize((350, 250))
        self.SetTitle('New Frame Title')
        self.Centre()
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

控制台输出:

[(, '&File'), (, '&Info')]

输出窗口: