python 调用ocx

1. 利用ocx名称

import win32com.client

w = win32com.client.Dispatch('Word.Application')
# 或者使用下面的方法,使用启动独立的进程:
# w = win32com.client.DispatchEx('Word.Application')

2. 利用classid

import win32com.client.gencache as win32

ocx_classid = '{3F166327-8030-4881-8BD2-EA25350E574A}'
ocx = win32.EnsureModule(ocx_classid, 0, 1, 0)

3. 实例

在wxpyton中引入ocx

用ocx函查看器查看我们要引用的ocx

python 调用ocx_第1张图片

classid取绿色框中的文本

ActiveXWrapper = MakeActiveXClass(ktocx.KTSEDocAxEx)

import wx
from wx.lib.activexwrapper import MakeActiveXClass
import win32com.client.gencache as win32

class MainFrame(wx.Frame):
    def __init__(self,parent=None,title="test"):
        super().__init__(parent,title=title,size=(900,800))
        
        box = wx.Panel(self, -1, style=wx.FULL_REPAINT_ON_RESIZE)
        self._ktocx(box)
        self.Centre()
        self.Show()
    
    def _ktocx(self,box):
        ocx_classid = '{5A79EFEB-0D35-4894-BC8C-CBA69803B5C3}'
        ktocx = win32.EnsureModule(ocx_classid, 0, 1, 0)
        if ktocx is None:
            wx.MessageBox('未安装凯特签章驱动', '错误', wx.OK | wx.ICON_WARNING)
            self.Close(True)

        ActiveXWrapper = MakeActiveXClass(ktocx.KTSEDocAxEx)
        self.ocx = ActiveXWrapper(box, -1, size=(945, 810))

if __name__ == "__main__":
    app = wx.App()
    frame = MainFrame()
    app.MainLoop()
     
        

 效果图:

python 调用ocx_第2张图片

你可能感兴趣的:(python)