這篇文章主要介紹了Python處理選單訊息操作,結合實例形式分析了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.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)
#:win32ui模組的安裝可直接使用pip
指令,如下:
##
pip install pypiwin32相關推薦:
以上是Python處理選單訊息操作範例的詳細內容。更多資訊請關注PHP中文網其他相關文章!