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


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

GetMenuLabel()函數是wxPython的wx.MenuBar類中存在的另一個函數。GeteMenuLabel()函數用於返回菜單欄中存在的菜單標簽。GetMenuLabel()僅占據菜單在菜單欄中的位置。

用法:
wx.MenuBar.GetMenuLabel(self, menuindex)

參數:

參數 輸入類型 描述
pos int 菜單在菜單欄上的位置,從零開始。

返回值:菜單標簽;如果找不到菜單,則為空字符串。

代碼示例:

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') 
  
        # STATIC TEXT WITH LABEL OF MENU AT POSITIO 1 
        st1 = wx.StaticText(self, label = menubar.GetMenuLabel(1),  
                                            style = wx.ALIGN_LEFT) 
  
def main():
    app = wx.App() 
    ex = Example(None) 
    ex.Show() 
    app.MainLoop() 
  
  
if __name__ == '__main__':
    main()

窗口:




相關用法


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