wxpython:wx.Menu 菜单示例

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

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值