最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python之wxPython菜單使用詳解

 更新時間:2014年09月28日 09:41:41   投稿:shichen2014  
這篇文章主要介紹了python中wxPython菜單使用方法,可實現(xiàn)給彈出菜單項添加圖標的功能,在Python程序設計中非常具有實用價值,需要的朋友可以參考下

本文實例講述了python中wxPython菜單的使用方法,分享給大家供大家參考。具體如下:

先來看看下面這段代碼:

import wx 
APP_EXIT=1  #定義一個控件ID 
 
class Example(wx.Frame): 
  def __init__(self, parent, id, title): 
    super(Example,self).__init__(parent, id, title)    #調(diào)用你類的初始化 
 
    self.InitUI()      #調(diào)用自身的函數(shù) 
 
  def InitUI(self):  #自定義的函數(shù),完成菜單的設置 
 
    menubar = wx.MenuBar()    #生成菜單欄 
    filemenu = wx.Menu()    #生成一個菜單 
 
 
    qmi = wx.MenuItem(filemenu, APP_EXIT, "Quit")   #生成一個菜單項 
    qmi.SetBitmap(wx.Bitmap("2.bmp"))    #給菜單項前面加個小圖標 
    filemenu.AppendItem(qmi)      #把菜單項加入到菜單中 
 
    menubar.Append(filemenu, "&File")    #把菜單加入到菜單欄中 
    self.SetMenuBar(menubar)      #把菜單欄加入到Frame框架中 
 
    self.Bind(wx.EVT_MENU, self.OnQuit, id=APP_EXIT)  #給菜單項加入事件處理 
 
    self.SetSize((300, 200))      #設置下Frame的大小,標題,和居中對齊 
    self.SetTitle("simple menu") 
    self.Centre() 
 
    self.Show(True)    #顯示框架 
 
  def OnQuit(self, e):  #自定義函數(shù) 響應菜單項   
    self.Close() 
 
def main(): 
 
  ex = wx.App()      #生成一個應用程序 
  Example(None, id=-1, title="main")  #調(diào)用我們的類 
  ex.MainLoop()#消息循環(huán) 
 
if __name__ == "__main__": 
  main() 

運行效果如下圖所示:

這里再來解釋下幾個API,官方文檔如下:

wxMenuItem* wxMenu::AppendSeparator()

Adds a separator to the end of the menu.
See also:
Append(), InsertSeparator()

wxMenuItem::wxMenuItem ( wxMenu *  parentMenu = NULL,
     int  id = wxID_SEPARATOR,
     const wxString &  text = wxEmptyString,
     const wxString &  helpString = wxEmptyString,
    wxItemKind  kind = wxITEM_NORMAL,
    wxMenu *  subMenu = NULL 
  )

Constructs a wxMenuItem object.
Menu items can be standard, or "stock menu items", or custom. For the standard menu items (such as commands to open a file, exit the program and so on, see Stock items for the full list) it is enough to specify just the stock ID and leave text and helpString empty. Some platforms (currently wxGTK only, and see the remark in SetBitmap() documentation) will also show standard bitmaps for stock menu items.
Leaving at least text empty for the stock menu items is actually strongly recommended as they will have appearance and keyboard interface (including standard accelerators) familiar to the user.
For the custom (non-stock) menu items, text must be specified and while helpString may be left empty, it's recommended to pass the item description (which is automatically shown by the library in the status bar when the menu item is selected) in this parameter.
Finally note that you can e.g. use a stock menu label without using its stock help string:
       
 // use all stock properties:
        helpMenu->Append(wxID_ABOUT);

        // use the stock label and the stock accelerator but not the stock help string:
        helpMenu->Append(wxID_ABOUT, "", "My custom help string");

        // use all stock properties except for the bitmap:
        wxMenuItem *mymenu = new wxMenuItem(helpMenu, wxID_ABOUT);
        mymenu->SetBitmap(wxArtProvider::GetBitmap(wxART_WARNING));
        helpMenu->Append(mymenu);
that is, stock properties are set independently one from the other.

Parameters:
  parentMenu  Menu that the menu item belongs to. Can be NULL if the item is going to be added to the menu later.
  id  Identifier for this menu item. May be wxID_SEPARATOR, in which case the given kind is ignored and taken to be wxITEM_SEPARATOR instead.
  text  Text for the menu item, as shown on the menu. See SetItemLabel() for more info.
  helpString  Optional help string that will be shown on the status bar.
  kind  May be wxITEM_SEPARATOR, wxITEM_NORMAL, wxITEM_CHECK or wxITEM_RADIO.
  subMenu  If non-NULL, indicates that the menu item is a submenu.

wxMenuItem* wxMenu::Append (  int  id,
     const wxString &  item = wxEmptyString,
     const wxString &  helpString = wxEmptyString,
    wxItemKind  kind = wxITEM_NORMAL 
  )     
Adds a menu item.
Parameters:
  id  The menu command identifier.
  item  The string to appear on the menu item. See wxMenuItem::SetItemLabel() for more details.
  helpString  An optional help string associated with the item. By default, the handler for the wxEVT_MENU_HIGHLIGHT event displays this string in the status line.
  kind  May be wxITEM_SEPARATOR, wxITEM_NORMAL, wxITEM_CHECK or wxITEM_RADIO.

Example:
        m_pFileMenu->Append(ID_NEW_FILE, "&New file\tCTRL+N", "Creates a new XYZ document");
or even better for stock menu items (see wxMenuItem::wxMenuItem):
        m_pFileMenu->Append(wxID_NEW, "", "Creates a new XYZ document");
Remarks:
This command can be used after the menu has been shown, as well as on initial creation of a menu or menubar.

希望本文所述對大家的Python程序設計有所幫助。

相關(guān)文章

  • python無限生成不重復(字母,數(shù)字,字符)組合的方法

    python無限生成不重復(字母,數(shù)字,字符)組合的方法

    今天小編就為大家分享一篇python無限生成不重復(字母,數(shù)字,字符)組合的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • Python+selenium點擊網(wǎng)頁上指定坐標的實例

    Python+selenium點擊網(wǎng)頁上指定坐標的實例

    今天小編就為大家分享一篇Python+selenium點擊網(wǎng)頁上指定坐標的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07
  • 基于matplotlib+tkinter實現(xiàn)簡單的繪圖系統(tǒng)

    基于matplotlib+tkinter實現(xiàn)簡單的繪圖系統(tǒng)

    在理解matplotlib嵌入到tkinter中的原理之后,就已經(jīng)具備了打造繪圖系統(tǒng)的技術(shù)基礎,所以本文來實現(xiàn)一個簡單的繪圖系統(tǒng),感興趣的小伙伴小伙伴可以了解一下
    2023-08-08
  • python 列表降維的實例講解

    python 列表降維的實例講解

    今天小編就為大家分享一篇python 列表降維的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • Python為人臉照片添加口罩實戰(zhàn)

    Python為人臉照片添加口罩實戰(zhàn)

    本文主要介紹了Python為人臉照片添加口罩實戰(zhàn),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • python break和continue用法對比

    python break和continue用法對比

    在本篇文章里小編給大家整理的是一篇關(guān)于python break和continue用法對比內(nèi)容,有需要的朋友們可以學習參考下。
    2021-06-06
  • python 時間 T 去掉 帶上ms 毫秒 時間格式的操作

    python 時間 T 去掉 帶上ms 毫秒 時間格式的操作

    這篇文章主要介紹了python 時間 T 去掉 帶上ms 毫秒 時間格式的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • python中的字符串切割 maxsplit

    python中的字符串切割 maxsplit

    這篇文章主要介紹了python中的字符串切割 maxsplit,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 詳解Python3 對象組合zip()和回退方式*zip

    詳解Python3 對象組合zip()和回退方式*zip

    這篇文章主要介紹了Python3 對象組合zip()和回退方式*zip詳解,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-05-05
  • Python django導出excel詳解

    Python django導出excel詳解

    這篇文章主要介紹了Python django導出excel的方法 ,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
    2021-11-11

最新評論

龙井市| 保亭| 万盛区| 凤阳县| 高安市| 遂昌县| 琼海市| 芜湖县| 黑水县| 新民市| 天门市| 阿克| 西青区| 上蔡县| 格尔木市| 政和县| 南漳县| 化州市| 平乐县| 忻城县| 桂平市| 东阳市| 泰兴市| 博乐市| 华宁县| 濮阳市| 阳高县| 泰顺县| 绥阳县| 邛崃市| 当雄县| 常德市| 崇明县| 陇西县| 桐梓县| 内丘县| 开封市| 吴江市| 新乡县| 沧源| 固阳县|