Python on Electron framework

后端 未结 4 1725
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 23:07

I am trying to write a cross-platform desktop app using web technologies (HTML5, CSS, and JS). I took a look at some frameworks and decided to use the Electron framework.

4条回答
  •  醉酒成梦
    2020-12-22 23:45

    You can use python-shell to communicate between Python and Node.js/Electron.

    python-shell provides an easy way to run Python scripts from Node.js with basic and efficient inter-process communication and better error handling.

    Using python-shell, you can:

    • spawn Python scripts in a child process;
    • switch between text, JSON and binary modes;
    • use custom parsers and formatters;
    • perform data transfers through stdin and stdout streams;
    • get stack traces when an error is thrown.

    In your terminal, make sure you are inside the root folder of your project and run the following command to install python-shell from npm:

    npm install --save python-shell 
    

    You can then simply run a Python shell using:

    var pyshell =  require('python-shell');
    
    pyshell.run('hello.py',  function  (err, results)  {
     if  (err)  throw err;
     console.log('hello.py finished.');
     console.log('results', results);
    });
    

    See more information from this tutorial

提交回复
热议问题