成长带走的不只是时光,还带走了那些不害怕失去的勇气。谢谢那些怀疑我的人,给我成长的洗礼,让我更加孤独。
本文实例讲述了Python基于win32ui模块创建弹出式菜单。分享给大家供大家参考,具体如下:
一、代码:
# -*- 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.haodaima.com - MFC GUI',WS_OVERLAPPEDWINDOW,\ (10,10,800,500),None,0,None) self.HookMessage(self.OnRClick,WM_RBUTTONDOWN) def OnClose(self): self.EndModalLoop(0) def OnRClick(self,param): submenu = win32ui.CreatePopupMenu() submenu.AppendMenu(MF_STRING,1054,'Copy') submenu.AppendMenu(MF_STRING,1055,'Paste') submenu.AppendMenu(MF_STRING,1056,None) submenu.AppendMenu(MF_STRING,1057,'Cut') flag = TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON submenu.TrackPopupMenu(param[5],flag,self) w = MyWnd() w.ShowWindow() w.UpdateWindow() w.RunModalLoop(1)
二、运行效果:
注:win32ui模块的安装可直接使用pip
命令,如下:
pip install pypiwin32
希望本文所述对大家Python程序设计有所帮助。
本文Python基于win32ui模块创建弹出式菜单示例到此结束。不怕你没能力,怕你有了能力以后却忘记了努力。小编再次感谢大家对我们的支持!