Skip to content

YeYongFen/electron-python-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Electron Application with python core

This article shows you how to develop a electron Application whose engine written in python

###How to communicate with fontend and backend ### We can use socket. Luckily, zerorpc fits our needs here because it supports Python and Node.js

Python part

import zerorpc
import sys

class HelloRPC(object):
    def hello(self, name):
		
        return "Hello, %s" % name

s = zerorpc.Server(HelloRPC())
s.bind("tcp://127.0.0.1:8888")
print("port:8888")
sys.stdout.flush()   //trigger callback  of child_process in nodejs
s.run()

nodejs part

we can use 'child_process.exec' to spawn Python script

let script = path.join(__dirname, "./dist/kk.exe")
var pyProc = require('child_process').spawn('python', [script, port])
pyProc.stdout.on('data', function (data) {  //listen the data form cmd
    console.log('output from cmd:' + data);
});

we can use 'child_process.execFile' to run the generated excutable

let script = path.join(__dirname, "./dist/kk.exe")
var pyProc = require('child_process').execFile(script)
pyProc.stdout.on('data', function (data) {  //listen the data form cmd
    console.log('output from cmd:' + data);
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published