亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

python之wxPython菜單使用詳解

系統 1519 0

本文實例講述了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)    #調用你類的初始化 
 
    self.InitUI()      #調用自身的函數 
 
  def InitUI(self):  #自定義的函數,完成菜單的設置 
 
    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):  #自定義函數 響應菜單項   
    self.Close() 
 
def main(): 
 
  ex = wx.App()      #生成一個應用程序 
  Example(None, id=-1, title="main")  #調用我們的類 
  ex.MainLoop()#消息循環 
 
if __name__ == "__main__": 
  main() 


          

運行效果如下圖所示:

python之wxPython菜單使用詳解_第1張圖片

這里再來解釋下幾個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程序設計有所幫助。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!??!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 天天操天天搞 | 免费的黄色网 | 青青草国产三级精品三级 | 欧美freesex呦交6_10 | 全免费a级毛片免费看不卡 全免费a级毛片免费看视频免 | 97久久国语露脸精品对白 | 99热最新| 久久频这里精品99香蕉久网址 | 久久久久久综合 | 手机福利片 | 日日夜夜国产 | 情欲综合网 | 咪咪在线视频 | 欧美片欧美日韩国产综合片 | 色噜噜狠狠色综合久 | 亚洲视频在线观看免费视频 | 米奇精品一区二区三区 | 狠狠干狠狠色 | a加勒比一本东京 | 国产美女免费国产 | 日日干天天| 91在线小视频 | 久久亚洲伊人 | 成人毛片国产a | 亚洲va欧美va | 欧美肥老太婆交 | 日韩亚洲一区中文字幕在线 | 天天爱夜夜爽 | 国产成人免费观看在线视频 | 国产第一页久久亚洲欧美国产 | 久久中文字幕一区二区 | 2020国产成人精品免费视频 | 国内久久 | 99久久久国产精品免费播放器 | 国产福利午夜 | 鲁啊鲁啊鲁在线视频播放 | 国产成人永久免费视 | 久草香蕉视频在线观看 | 伊人骚| 国产一区高清视频 | 香蕉黄色网|