亲宝软件园·资讯

展开

Python创建普通菜单 Python创建普通菜单示例【基于win32ui模块】

chengqiuming 人气:5
想了解Python创建普通菜单示例【基于win32ui模块】的相关内容吗,chengqiuming在本文为您仔细讲解Python创建普通菜单的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Python,创建,普通菜单,win32ui模块,下面大家一起来学习吧。

本文实例讲述了Python创建普通菜单的方法。分享给大家供大家参考,具体如下:

一、代码

# -*- coding:utf-8 -*-
#! python3
import win32ui
import win32api
from win32con import *
from pywin.mfc import window
class MyWnd(window.Wnd):
  def __init__ (self):
    window.Wnd.__init__(self,win32ui.CreateWnd())
    self._obj_.CreateWindowEx(WS_EX_CLIENTEDGE,\
                 win32ui.RegisterWndClass(0,0,COLOR_WINDOW+1),\
                 'www.qb5200.com - MFC GUI',WS_OVERLAPPEDWINDOW,\
                 (10,10,800,800),None,0,None)
    submenu = win32ui.CreateMenu()
    menu = win32ui.CreateMenu()
    submenu.AppendMenu(MF_STRING,1051,'&Open')
    submenu.AppendMenu(MF_STRING,1052,'&Close')
    submenu.AppendMenu(MF_STRING,1053,'&Save')
    menu.AppendMenu(MF_STRING|MF_POPUP,submenu.GetHandle(),'&File')
    submenu = win32ui.CreateMenu()
    submenu.AppendMenu(MF_STRING,1054,'&Copy')
    submenu.AppendMenu(MF_STRING,1055,'&Paste')
    submenu.AppendMenu(MF_STRING,1056,None)
    submenu.AppendMenu(MF_STRING,1057,'&Cut')
    menu.AppendMenu(MF_STRING|MF_POPUP,submenu.GetHandle(),'&Edit')
    submenu = win32ui.CreateMenu()
    submenu.AppendMenu(MF_STRING,1058,'Tools')
    submenu.AppendMenu(MF_STRING|MF_GRAYED,1059,'Setting')
    m = win32ui.CreateMenu()
    m.AppendMenu(MF_STRING|MF_POPUP|MF_CHECKED,submenu.GetHandle(),'Option')
    menu.AppendMenu(MF_STRING|MF_POPUP,m.GetHandle(),'&Other')
    self._obj_.SetMenu(menu)
  def OnClose(self):
    self.EndModalLoop(0)
w = MyWnd()
w.ShowWindow()
w.UpdateWindow()
w.RunModalLoop(1)

二、运行效果:

注:win32ui模块的安装可直接使用pip命令,如下:

pip install pypiwin32

希望本文所述对大家Python程序设计有所帮助。

加载全部内容

相关教程
猜你喜欢
用户评论