Is Electron a good choice for adding a front-end to my python programs?
Posted by Quiet_Isopod8373@reddit | learnprogramming | View on Reddit | 20 comments
Hi everyone! My main programming language is Python, and I've developed a lot of applications with it, but none with a visual interface. I’d like to start creating something with a GUI.
I learned about Electron from asking GPT as a modern way to build Windows applications, and it even gave me a Discord example. However, I’m not sure if Electron is the right framework to start with for visual interfaces. I also don’t know if it's practical to use Python alongside JavaScript and TypeScript in Electron. I only know the basics of JavaScript, and I’m not ready to commit to learning it in depth.
Would Electron be a good choice for this kind of project, or is there a better alternative for someone with my background?
ericsnekbytes@reddit
You can do it all in Python with Qt, I made a quick start guide with tiny examples here :)
unhott@reddit
Something that has python like syntax that helps you build interfaces quickly, not many people use it in this manner, but Godot. It's a game engine. It has a nice user interface to developing in it, and the concepts would translate if you wanted to switch to something else later. I am pretty sure it can also export to html.
If you just want a basic interface where users provide data and get some result back, web is not too bad. Perfect use case for a good old fashioned html form. Rather than run code on an application on a computer, you run the code on a server for people. They can interact with an html front end. You can add a lot of interactivity with htmx as well, without having to dive into the js realm, with all of its complexity and baggage.
The last options are gui development libraries in python. You can ask your preferred LLM for options.
FORGOT123456@reddit
another free, tiny game engine that may be interesting - not python, but lua - would be the defold engine. 1 package download - complete solution. it's a very small and self-contained editor etc.
search up raysan5 on github a number of projects, raygui being an immediate mode gui library. pretty interesting. written in plain c, though - probably not what you are interested in, though it looks nice, to me.
icedrift@reddit
You know this is actually pretty clever and completely slipped my mind. I worked at a company that had some internal tools written in unity for this very reason. OP would have to scrap their current project and rewrite it in godot but the editor would likely make that process faster and more intuitive than learning web concepts.
lt947329@reddit
The modern standard mapmaking tools for tabletop RPGS like D&D are Dungeondraft and Wonderdraft, both made in Godot.
They are so popular, their open file format (dd2vtt) has become an industry standard for uploading “rich content” maps to virtual tabletops.
androgynyjoe@reddit
Similarly, PyGame can also be an option in some circumstances.
Maleficent_Main2426@reddit
You can use QT
funkenpedro@reddit
I gave up on Python for this very problem. Interesting to know it still exists. You can get a button on a web page to perform an action in JavaScript and understand how it works in under an hour (no tooling required, you can write it in notepad if you want) I’m guessing. See how long it takes you to do the same with Qt any other framework/library.
minneyar@reddit
If you want to make a GUI using Python, I'd strongly recommend using Qt, which is a very powerful, well-supported widget toolkit that can make native-looking applications. Check out Qt for Python: https://doc.qt.io/qtforpython-6/
Whole_Bid_360@reddit
OP if you are making a desktop app where the data is stored on the users machine and not your own server I suggest you stick to using one language for the gui and for the logic. If you don't you have to figure out how to make both your apps talk to each over which honestly is introducing unnecessary complexity into your app. Either build it all in python or all in javascript.
thebadslime@reddit
You can try tkinter too.
GrilledCheezus_@reddit
Sure, if you don't really care about the appearance.
icedrift@reddit
Electron is great for what it is but I wouldn't recommend trying to use it as a frontend for a python application. It is doable but there's a reason it isn't commonplace, you would be essentially creating 2 separate applications in different languages and need to implement a rest api between them. For smaller applications where you don't need the flexibility of a browser renderer this is massively overkill, especially if you don't know much javascript.
You'd be better off sticking to python, learning tkinter, and finding a modern theme that looks good.
TomWithTime@reddit
Could be an interesting idea if they want to turn the Python program into a server that can service many clients, though it might be better to make a web page instead of an electron application. The only benefit to electron them would be getting out of the sandbox or doing other native things that probably don't matter if the goal is communicating with the Python application.
I used to love the idea of UI kits being part of a language like Java swing, but it's been at least 10 years since I've bothered to make a desktop application instead of a web page.
icedrift@reddit
Nah that defeats the entire point of electron. You can ship a python backend in electron with some third party tools but those would still be their own instances on the user's machine. What you're describing would still require a separate server serving those local backends.
Practically speaking I completely agree with you, the browser's features and robustness across environments is nothing short of incredible for frontend development but to a hobbiest who hasn't touched web dev and just wants a GUI for their [insert language] command line application it's not worth the time investment.
TomWithTime@reddit
Fair enough. Java wasn't too terrible at this in 2008 so I suspect it's even easier now
zdxqvr@reddit
I am not super familiar with Python development outside of scripting. But I do have experience with electron. Unless you are using JavaScrip, I really wouldn't think it would be a good fit. It was designed to bring web technologies to the desktop. I feel it would be more trouble than it's worth to use it with Python.
__Loot__@reddit
Id do the front end in Django or whatever its called Not a python dev but am JavaScript dev and electron has been such a headache for me but might be a skill issue not sure. But definitely go type script if your JavaScript. I love JavaScript but if your going to make a decent sized program you need type script imo
icedrift@reddit
OP said they weren't interested learning javascript so I doubt they'd want to invest all of that time to learn web app architecture just to create a GUI for some headless python programs. Funny enough though one of the most common ways to make django apps run in a desktop environment is to wrap them in electron.
__Loot__@reddit
Yea I dont know if django is front or backend or both 😂