pip install wxpython==4.2
wxPython-4.2.0-cp37-cp37m-win_amd64.whl (18.0 MB)
Successfully installed wxpython-4.2.0
cd \Python37\Scripts
wxdemo.exe 下载 wxPython-demo-4.2.0.tar.gz
wxdocs.exe 下载 wxPython-docs-4.2.0.tar.gz
编写 test_wx_menu.py 如下
# -*- coding: utf-8 -*-
import os
import sys
import time
import wx
import images
# images.py 在 C:\Users\username\AppData\Local\wxPython\wxPython-demo-4.2.0\demo\
#-------------------------------------------------------------------
class MyFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Playing with menus', size=(600,300))
self.CenterOnScreen()
self.CreateStatusBar()
self.SetStatusText("This is the statusbar")
tc = wx.TextCtrl(self, -1, """
A bunch of bogus menus have been created for this frame. You
can play around with them to see how they behave and then
check the source for this sample to see how to implement them.
""", style=wx.TE_READONLY|wx.TE_MULTILINE)
# Prepare the menu bar
menuBar = wx.MenuBar()
# 1st menu from left
menu1 = wx.Menu()
menu1.Append(101, "&Mercury", "This the text in the Statusbar")
menu1.Append(102, "&Venus", "")
if False:
# This is how you would create the menu item if you want to
# change some of the visible attributes.
item = wx.MenuItem(id=103, text="&Earth", helpString="You may select Earth too")
item.SetFont(wx.Font(wx.FontInfo(10).Bold()))
menu1.Append(item)
else:
# But we'll just do it the normal way for this sample
menu1.Append(103, "&Earth", "You may select Earth too")
menu1.AppendSeparator()
menu1.Append(104, "&Close", "Close this frame")
# Add menu to the menu bar
menuBar.Append(menu1, "&Planets")
# 2nd menu from left
menu2 = wx.Menu()
menu2.Append(201, "Hydrogen")
menu2.Append(202, "Helium")
# a submenu in the 2nd menu
submenu = wx.Menu()
submenu.Append(2031,"Lanthanium")
submenu.Append(2032,"Cerium")
submenu.Append(2

本文详细介绍了如何在Python中使用wxPython库创建菜单栏和菜单项,包括普通菜单、下拉菜单、复选菜单和单选菜单的实现,以及菜单事件的绑定和处理。
最低0.47元/天 解锁文章
3004

被折叠的 条评论
为什么被折叠?



