Python processing Menu Message Operation example

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.