python的sciter库Pysciter安装教程(win32 + win64)

 

Pysciter是一个结合HTMLPython编写桌面软件个三方库

注:无论是32位还是64位电脑,建议安装32位的sciter,这样写出来的软件可以在win32和win64电脑上都可以运行(前提python安装了32位的),下面介绍32位sciter安装方法(32位电脑和64位电脑安装方式有所区别,会分别说明)。

 

一:sciter-sdk相关配置:

1.下载 sciter-sdk中32位的 sciter.dll 文件

https://github.com/c-smile/sciter-sdk/blob/master/bin/32/sciter.dll

 

2. 注册sciter.dll

32位系统电脑:把sciter.dll复制到C:\Windows\System32目录,打开DOS窗口输入命令(管理员身份运行)

regsvr32 /s sciter.dll

64位系统电脑:把sciter.dll复制到C:\Windows\SysWOW64目录,然后在C:\Windows\SysWOW64目录中找到cmd.exe以管理员身份运行,然后输入命令:

regsvr32 /s sciter.dll

如:

 

3. 下载 pysciter 并解压到D盘

https://codeload.github.com/sciter-sdk/pysciter/zip/master

 

4. 在pysciter-master目录中打开命令行,输入命令

python setup.py install

此时就会将pysciter安装到python第三方安装包的目录下,我的是 D:\Python\Python36\Lib\site-packages\PySciter-0.4.25-py3.6.egg

 

5. 修改pysciter源码

 用编辑器打开 D:\Python\Python36\Lib\site-packages\PySciter-0.4.25-py3.6.egg\sciter\capi\sctypes.py

第101行把SCITER_DLL_NAME = "sciter" 修改为 注册sciter.dll所在位置(去掉后缀):

32位:SCITER_DLL_NAME = "C:\Windows\System32\sciter"

64位:SCITER_DLL_NAME = "C:\Windows\SysWOW64\sciter"

 

6. 运行实例查看效果

python pysciter.py

出现上图表示安装正常

 

7. python的idea中使用sciter,包括python中和html交互,示例如下:

import sciter
import time
import threading

def run(self):
    while 1:
        time.sleep(2)
        # 调用html中方法
        self.eval_script('hello("42");')

class Frame(sciter.Window):
    def __init__(self):
        super().__init__(ismain=True, uni_theme=True)
        pass

    @sciter.script
    def PythonCall(self, arg):
        print("参数:", str(arg))
        return "通信成功了,返回值:" + str(arg) + ' -_-'

    @sciter.script
    def inti(self):
        # 启动独立的线程
        t = threading.Thread(target=run, args=(self,))
        t.start()

if __name__ == '__main__':
    import os
    htm = os.path.join(os.path.dirname(__file__), 'Gui/pysciter.html')   #pysciter.html文件编码格式必须 Unix(LF) UTF-8-BOM 以防止中文乱码
    frame = Frame()
    frame.load_file(htm)
    frame.run_app()

Gui/pysciter.html(pysciter.html文件编码格式必须 Unix(LF) UTF-8-BOM 以防止中文乱码):

<html window-icon="icon.png">
  <head>
    <title>PySciter示例</title>
    <style>
      html {
        background: radial-gradient(75% 75%, circle farthest-side, white, orange, rgb(0,0,204));
        color:#fff;
      }
      html:rtl {
        mapping: left-to-right(background);
      }
    </style>
    <script type="text/tiscript">
      //ti调用py方法
      view.cc = "haha哈";
      $(button#ti2py).on("click", function() {
        var answer = view.PythonCall(view.cc);
        $(body).$append(<h1#test>{answer}</h1>);
      })

      //py调用ti方法
      function hello(who) {
          $(body).$append(<h1#test>{who}</h1>);
      }
      view.inti()

      //输出语句
      //stdout.println("2 + 3 = ");
    </script>
  </head>
<body>
  <h1>Pythonic Sciter Application</h1>
  <button #ti2py>ti调用py方法</button>
</body>
</html>

 

转载于:https://www.cnblogs.com/007sx/p/9439179.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值