0

I'm making my first project with Electron. It's a password manager and generator. My main objective right now is to display a randomly generated password into the app using Python Shell, but can't seem to do it.

Python code:

from random import choice
import string

def generator():
  value =  string.ascii_letters + string.digits + string.punctuation
  password = ""

  for i in range(0, 21):
     random = choice(value)
     password += random

print(password)
generator()

Javascript Code:

function getGenerator() {
var generate = document.getElementById("result")
var {PythonShell} = require("python-shell")
var path = require("path")

var options = {
    scriptPath : path.join(__dirname, '/../_engine/'),
    pythonPath : '/Light/AppData/Local/Microsoft/WindowsApps/python3'
}

var pyshell = new PythonShell('generator.py', options)

pyshell.on('message', function(message) {
    swal(message);
 })
}

I have no idea what to do really. I'm a newbie with JavaScript so I'm kinda desperate for a direction. Would be really grateful if someone could help me.

  • What is happening? Are you getting error messages? Also, electron has a main process and a renderer process. The main process is able to run python scripts, the renderer process does in-browser stuff like swal. You cannot do both in a single script. Also, implementing this password generator in JS is extremely simple, so is this about learning how to use python or just about generating the password? Because if the latter, you don't need any of this: https://jsfiddle.net/38usyqef/ –  Aug 28 '22 at 22:20
  • No errors at all. No warnings either. The app starts but the button that is supposed to start the Python script and generate the password doesn't really seem to do anything. I'm making this program with a friend of mine and we've built a version of it running entirely in JS. It's just that we really wanted to create a project that uses both programming languages we've been studying(Python and Javascript). So yeah, we know it's much easier to use JS for the password generator than Python, but we really wanted the challenge to combine them both in a single app. – Victor Svart Aug 28 '22 at 22:48
  • 1
    Does this answer your question? [Python not printing output](https://stackoverflow.com/questions/55325145/python-not-printing-output) – snwflk Aug 29 '22 at 01:30

0 Answers0