這篇文章主要介紹了Python基於win32ui模組創建彈出式選單,結合實例形式分析了Python使用win32ui模組創建彈出式選單的具體步驟與相關操作技巧,並附帶說明了win32ui模組的安裝命令,需要的朋友可以參考下
本文實例講述了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.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)
##註: win32ui模組的安裝可直接使用pip指令,如下:
pip install pypiwin32
使用Python透過win32 COM實作Word文件的寫入與保存方法
以上是Python基於win32ui模組創建彈出式選單的詳細內容。更多資訊請關注PHP中文網其他相關文章!