Import WX App_exit=1 #定义一个控件ID class Example (WX. Frame): Def __init__ (self, parent, ID, title): Super (Example,self). __INIT__ (parent, ID, title) #调用你类的初始化 Sel F.initui () #调用自身的函数 def initui (self): #自定义的函数, complete the settings for the menu 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 (()) #设置下Frame的大小, title, and center align Self. Settitle ("simple Menu") self. Centre () self. Show (True) #显示框架 def onquit (self, e): #自定义函数 response menu item self. Close () def main (): ex = WX. APP () #生成一个应用程序 Example (None, Id=-1, title= "main") #调用我们的类 ex. Mainloop () #消息循环 if __name__ = = "__main__": Main ()
The effect is as follows:
Python's Wxpython menu using the detailed