在本文中,我們將學習與wxPython的wx.MenuBar類關聯的GetMenus()函數。 GetMenus()函數僅返回MenuBar中菜單的(菜單,標簽)項目列表。
GetMenus()函數中不需要參數。
用法: wx.MenuBar.GetMenus(self)
參數: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()
控製台輸出:
[(<wx._core.Menu object at 0x00000075049250D0>, '&File'), (<wx._core.Menu object at 0x0000007504925160>, '&Info')]
輸出窗口:
相關用法
- wxPython wx.MenuItem IsSubMenu()用法及代碼示例
- wxPython wx.ToolBar SetDropdownMenu()用法及代碼示例
- wxPython wx.StaticLine IsVertical()用法及代碼示例
- wxPython wx.Button SetAuthNeeded()用法及代碼示例
- wxPython wx.MenuItem IsSeparator()用法及代碼示例
- wxPython wx.MenuBar IsChecked()用法及代碼示例
- wxPython wx.MenuItem SetBackgroundColour()用法及代碼示例
- wxPython wx.BitmapButton GetClassDefaultAttributes()用法及代碼示例
- wxPython wx.Button SetDefault()用法及代碼示例
- wxPython wx.MenuBar IsEnabled()用法及代碼示例
- wxPython InsertSimpleTool()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – GetMenus() function in wx.MenuBar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。