This article mainly introduced the Python processing menu message operation, combined with the instance form analysis Python based on the Win32ui Module Realization Menu creation and the menu item response related operation skill, needs the friend can refer to the next
The examples in this article describe Python processing menu message operations. Share to everyone for your reference, as follows:
One, the code
#-*-Coding:utf-8-*-#! Python3import win32uiimport win32apifrom win32con import *from pywin.mfc import windowclass 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) 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 ') self._obj_. SetMenu (menu) self. Hookcommand (self. menuclick,1051) self. Hookcommand (self. menuclick,1052) self. Hookcommand (self. menuclick,1053) def OnClose (self): self. Endmodalloop (0) def menuclick (Self,lparam,wparam): if LParam = = 1051:self. MessageBox (' Open ', ' Python ', MB_OK) elif LParam = = 1053:self. MessageBox (' Sava ', ' Python ', MB_OK) else:self. OnClose () W = Mywnd () W.showwindow () W.updatewindow () W.runmodalloop (1)
Note: The win32ui module can be installed directly using the pip command as follows:
Pip Install Pypiwin32