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


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

在本文中,我們將學習與wxPython的wx.MenuBar類關聯的Insert()函數。因此Insert()函數是wx.MenuBar類中非常重要的函數。 Insert()函數將菜單在給定位置插入菜單欄。

在位置0插入菜單會將其插入菜單的最開始,在位置GetMenuCount插入與調用Append相同。

用法: wx.MenuBar.Insert(self, pos, menu, title)

參數:

參數 輸入類型 描述
pos int 新菜單在菜單欄中的位置
menu wx.Menu 要添加的菜單。 wx.MenuBar擁有菜單並將其釋放。
title string 菜單標題。

代碼示例:

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') 
  
        # INSERT A NEW MENU IN MENUBAR AT POSITION 0 
        self.menubar.Insert(0, self.fileMenu2, '&New Menu') 
        self.SetMenuBar(self.menubar) 
        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()

輸出:




相關用法


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