This article mainly introduces Python to create a pop-up menu based on the win32ui module. It analyzes the specific steps and related operating techniques of using the win32ui module to create a pop-up menu in Python with examples. It also explains the installation command of the win32ui module. You need to Friends can refer to the following example
This article describes the creation of a pop-up menu in Python based on the win32ui module. Share it with everyone for your reference, the details are as follows:
1. Code:
# -*- 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.jb51.net - 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)
Note:The win32uimodule can be installed directly using thepip
command, as follows:
pip install pypiwin32
The above is the entire content of this article. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
Use Python to write and save Word documents through win32 COM
The above is the detailed content of Python creates pop-up menu based on win32ui module. For more information, please follow other related articles on the PHP Chinese website!