使用win32com模块开发window activex的示例:(如果你还没有装win32com模块的话,请到http://python.net/crew/skippy/win32/downloads.html下载)。
复制代码 代码如下:
# simplecomserver.py
class pythonutilities:
_public_methods_ = ['splitstring']
_reg_progid_ = python.utilities
_reg_clsid_ = {a6688635-62f5-41cb-af54-cba84c2f0f86}
def splitstring(self, val):
return hello world , val
if __name__ == '__main__':
print registering com server...
import win32com.server.register
win32com.server.register.usecommandline(pythonutilities)
在console下运行:python simplecomserver.py
在html页面中调用该activex组件:
复制代码 代码如下:
window.onload = function(){
var obj = new activexobject(python.utilities);
alert(obj.splitstring(hel));
}