當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


wxPython wx.MenuBar GetMeuCount()用法及代碼示例

GetMenuCount()函數是wxPython的wx.MenuBar類中存在的另一個函數。GetMenuCount()函數返回MenuBar中存在的菜單總數。它不帶參數。

用法: wx.MenuBar.GetMenuCount(self)

參數:GetMenuItem()中沒有參數

返回:返回此菜單欄中的菜單數。

碼:

將靜態文本標簽設置為菜單項的總數。

import wx 
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kw):
        super(Example, self).__init__(*args, **kw) 
  
        # create MenuBar using MenuBar() function 
        menubar = wx.MenuBar() 
  
        # add menu to MenuBar 
        fm1 = wx.Menu() 
        fileitem = fm1.Append(20, "one") 
  
        fm2 = wx.Menu() 
        fileitem2 = fm2.Append(21, "two") 
        menubar.Append(fm1, '&Menu_one') 
        menubar.Append(fm2, '&Menu_two') 
        self.SetMenuBar(menubar) 
        self.SetSize((300, 200)) 
        self.SetTitle('Menu Bar') 
        st1 = wx.StaticText(self, label ="Total Menus:" + str(menubar.GetMenuCount()),  
                                                                 style = wx.ALIGN_LEFT) 
  
def main():
    app = wx.App() 
    ex = Example(None) 
    ex.Show() 
    app.MainLoop() 
  
  
if __name__ == '__main__':
    main()

輸出:




相關用法


注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – GetMeuCount() function in wx.MenuBar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。