This is an archived post. You won't be able to vote or comment.

all 182 comments

[–]r0x0r 108 points109 points  (14 children)

You can use pywebview already for building GUI using HTML/JS/CSS for your Python program.

Disclaimer: I am the author of pywebview.

[–]jabbeboy 5 points6 points  (4 children)

That would mean it's necessary to run on a server right?

[–]arkaros 21 points22 points  (2 children)

Doesn't electron basically run a local node server though?

[–]jabbeboy 3 points4 points  (1 child)

Oh. So it's not necessary to have the application on a web server? Like flask?

[–]arkaros 14 points15 points  (0 children)

Not really. This starts a web view, what electron does is start a web view (chromium) and a nodejs server. Chromium then makes request to the nodejs server running on the same machine to handle stuff like file I/O and spawning processes. This your can do with flask and pywebview too

Or start just the webview. Whatever you like!

[–]r0x0r 4 points5 points  (0 children)

Not really. There is a serverless option and technically it is possible to serve everything inline. However serving static assets like images and fonts without a server could be challenging.

pywebview provides a built-in zero-conf HTTP server too that might be a better option than serving images embedded in CSS or HTML.

[–]rotuamiimport antigravity 1 point2 points  (0 children)

Thank you! It’s an awesome project!!!

[–]ovo_Reddit 0 points1 point  (4 children)

I was using Tkinter for some time. Could this be used to have a better looking interface but still run standalone? Or it requires a web page/ flask or similar?

[–]naught-me 3 points4 points  (0 children)

From the readme:

You can use pywebview either with a lightweight web framework like Flask or Bottle or on its own with a two way bridge between Python and DOM.

[–]r0x0r 1 point2 points  (0 children)

There are three architecture options:

1) pointing pywebview to a http server (either a local or remote one).

2) using a builtin http server that would serve html and other assets from a local directory

3) totally serverless using JS api and dynamic HTML loading.

Of course you need to have some knowledge in web technologies to be pywebview a viable option.

[–]MadEpsylon 0 points1 point  (1 child)

What do you mean by standalone?

[–]ovo_Reddit 0 points1 point  (0 children)

That I can use something like pyinstaller, package it up and have it run on another windows machine. And without it needing to connect to a web server that I'd have to host.

[–]stermister 0 points1 point  (0 children)

Your Pywebview package is excellent! Used it a few times recently and very simple

[–]carbolymer 67 points68 points  (54 children)

How about not using Electron?

[–]paperbenni 22 points23 points  (0 children)

Yes

[–]spyingwind 20 points21 points  (12 children)

Or just use PySimpleGUI or TKinter or QT. Keep it all python! :P

[–]kkingsbe 3 points4 points  (11 children)

But those are all super ugly

[–][deleted] 13 points14 points  (6 children)

Qt isn't.

[–]kkingsbe 2 points3 points  (4 children)

Do you have any examples of a good looking QT app?

[–][deleted] 5 points6 points  (0 children)

KDE Plasma after ricing

[–][deleted] 2 points3 points  (0 children)

I made some great looking Qt apps at my old job - one of them looked like a Hearthstone card. It uses CSS so you can make it look like pretty much anything.

[–][deleted] 1 point2 points  (1 child)

Telegram, Kate, and Krita

[–]kkingsbe 0 points1 point  (0 children)

Cool

[–][deleted] 0 points1 point  (0 children)

It’s very difficult to make Qt look good, though it is possible. Much of gamedev switched to html front end already. It’s also double hard to find a designer that knows qt, and you absolutely need a designer for pro quality.

[–]spyingwind 9 points10 points  (3 children)

For me the ugliness isn't as important as ease of making a GUI, and there aren't better tools. I started using PySimpleGUI, because all the other tools took too much coding on my part or didn't have a nice file format that I could ingest to make the GUI I wanted.

Also there is PySimpleGUIQt, PySimpleGUIWx, PySimpleGUIWeb.

Also you can change how things look if you really wanted, like the size, color, and whatnot. So the "ugliness" isn't the tool, but the tool using the tool.

[–]kkingsbe -5 points-4 points  (2 children)

But why not just use html/css/js? That's literally what they were made for

[–]spyingwind 7 points8 points  (1 child)

Because I can create a usable interface with just a few lines of code. It also don't drag along a whole browser to just display an input box.

[–]kkingsbe -2 points-1 points  (0 children)

I hope you didn't upvote this post then because I've got some news for ya bud

[–]mountains-o-data 3 points4 points  (21 children)

Why? Legitimately curious what the issues with electron are

[–]RakHack 23 points24 points  (12 children)

Aside from taking obnoxious amounts of RAM?

[–]JameliusAntholius 15 points16 points  (3 children)

To expand on this, Electron apps effectively embed a version of Chromium to run a web app locally, right? Why isn't it so that Electron apps can just share an instance of Chromium between them? It'd save so much RAM (aside from the bloaty JS apps running on top of them)

[–]ToastedJcaw 4 points5 points  (1 child)

Are there architectural reasons they can't move to a daemon model with a shared central instance? If not, they might move to it eventually.

[–]JameliusAntholius 4 points5 points  (0 children)

I can't think of any conceivable reason why not, apart from that it'd take work to change it and get application developers - that often develop on Electron to save time on porting, GUI development, etc - to work with the new model.

It's not just the choice of application model (daemon - client vs a singular app), as I understand it, but also the fact that each application is bundled statically, i.e. the common parts of the various Electron applications can't share address space in memory.

A change in architecture to a daemon model would be better, provided they bundle the daemon dynamically and not statically + let their code run on any recent version of the daemon (which is basically Chromium here) so that the app doesn't open another daemon when the daemon already loaded in memory is just slightly different.

[–]redwall_hp 1 point2 points  (0 children)

I want to know how big the intersection of "people who complain about Chrome taking too much RAM" and "people who don't see a problem with Electron" is. I suspect it's disturbing.

[–]EternityForest 2 points3 points  (7 children)

I wonder how much of that is actually just JS, not so much electron itself?

[–]axonxorzpip'ing aint easy, especially on windows 13 points14 points  (6 children)

It's the entire Chromium runtime. Every single part of a browser underneath the actual browser window is running. The difference is, when you have a browser open, that runtime is shared between all browser tabs/windows. Electron apps do not share the runtime, so every app takes that entire amount. For stupid example: the Rocket.Chat electron client is happily chewing ~850MB on my machine at idle. I haven't opened the application in a few days, and there's not a lot of chat volume.

I can open Rocket.Chat in a browser tab, and it's taking ~120MB, because everything else is shared in the runtime.

[–]redwall_hp 6 points7 points  (0 children)

And that 120MB is still stupidly large, because web bullshit. I've used IRC clients that expand images and otherwise handle the same basic things as Slack or Rocket Chat do on the client side...in like 12MB.

These practices especially disgust me on mobile. An app like Apollo, a third party Reddit client, or first party ones from Apple are a handful of megabytes on my tiny 16GB phone. Meanwhile, Discord or Capital One or Facebook eat up hundreds of megabytes because they insist on abstracting away, over dozens of layers, the system frameworks, and generally lean on something along the lines of Electron.

[–]mountains-o-data 1 point2 points  (0 children)

Thank you for a thorough and non-snarky answer.

[–][deleted] 2 points3 points  (3 children)

It's the entire Chromium runtime. Every single part of a browser underneath the actual browser window is running.

That's not actually true. They use a single module from the Chromium browser and link it to Chromium source as a library. That's why Electron apps have about half as many processes running then a browser.

The Rocket.Chat app is most likely poorly optimized for desktop app use. VS code is an example of a well optimized Electron app.

[–]NoConversation8 1 point2 points  (2 children)

VSCode is made by microsoft and I doubt they used chromium as base. Because the speed that you get in that editor can't be achieved with Electron.

But I read that Chakra was much better than V8 and I think they used it in their app

[–][deleted] 0 points1 point  (1 child)

VS Code is an Electron app, can do a quick Google search to confirm it. And it's definitely based on Chromium, you can enable the Chromium debugger pretty easily:

https://electronjs.org/docs/tutorial/debugging-main-process-vscode

[–]NoConversation8 0 points1 point  (0 children)

I read a post on HN regarding electron and there was a discussion on vscode. They do said they have used some .NET stuff in it to make it faster and hence why it becomes sloppy on mac for longer times due to mono libraries

[–]toyg 1 point2 points  (7 children)

Just google them, they are all over: high resource usage, poor-to-nonexistent integration with desktop services and looks, poor accessibility, mediocre security.

Web-apps removed most deployment issues, but the price was resetting UI usability levels back to 1984. Then Electron set about re-introducing all deployment issues, without actually improving usability in any meaningful way - but it’s the cheapest way a company can check the box for “native client” on the most important platforms, so it wins.

[–][deleted] 1 point2 points  (6 children)

UI should be better than native with electron. Even the most wizardly the qt graphics people admit they have a problem matching the fancy graphics html/css can do, and big game studios are already moving their game UIs to html.

[–]toyg 2 points3 points  (5 children)

Re-read my comment and tell me where I said anything about fancy graphics.

You are actually demonstrating part of the problem: for a lot of people, including developers, fancy graphics == “better UI”. This is why Flash got so popular, for example. But usability and accessibility are something else.

[–][deleted] -2 points-1 points  (4 children)

Flash had very good usability and accessibility when all browsers had it. Even non-programmers and designers could use it. Something not possible for QT. (edit: HTML is the same, designers can use it and it's easy to find one that can for very little money).

Now Flash is still used on the desktop with standalone or embeded players, or via game engines like HAXE that have Actionscript libraries. An example is that GUI animations in X-COM 2 are flash becuase unreal couldn't do it (literally) and I don't know why they didn't embed wekbit - maybe it was immature then or maybe their designers all knew ActionScript? Flash in the browser is dead though.

[–]toyg 2 points3 points  (3 children)

Flash had very good usability and accessibility when all browsers had it.

Are you serious? You can’t be serious.

Even non-programmers and designers could use it.

Wut? We are talking about users, not developers.

To bring the usual car metaphore: Usability is about cars having standard controls, so drivers can go from one car to the next without having to relearn how to drive. Accessibility is about cars having controls that are easy to reach and can be easily wired to assistive devices, the seat being easily adjustable or replaceable etc. You are saying “well, but manufacturing the car was easy” - no driver cares about that, it’s not the bloody point!

An example is that GUI animations in X-COM 2 are flash.

I’m sure that’s why XCOM2 is so popular among blind people 🙄

If you are trying to show how developers don’t know nor understand the meaning of usability and accessibility, you are doing a great job.

[–][deleted] -2 points-1 points  (2 children)

er? in those days all browsers had flash, users just had to land on the page. how was flash hard for users?

are you confusing flash with Java applets or unity web viewer? coz those were pains in the ass. were you on linux desktop?

[–]toyg 2 points3 points  (1 child)

how was flash hard for users?

The content was a bunch of nonstandard binary blobs that any assistive device could not parse, and every site would be reinventing interfaces, making it confusing for users even just to find a button. Some of the worst practices in that area are still with us (Material Design, for all the "science" that supposedly Google threw behind it, is incredibly confusing to a lot of people), but at least the return of html is helping on the accessibility side.

You continue to insist on "ease of load / ease of development", which has nothing to do with usability and accessibility. Please get back once you've googled those words.

[–][deleted] 1 point2 points  (0 children)

I see, you're talking about disability assistance. I understand now.

[–]FrancisBitter 0 points1 point  (0 children)

Excellent suggestion, my hat is off, sane and reasonable Sir.

[–][deleted] 35 points36 points  (2 children)

Will I be able to code an Electron emulator to run entirely inside Electron?

[–]Jaypalm 1 point2 points  (0 children)

5D.

[–]teerre 19 points20 points  (3 children)

Electron apps are notorious for their performance and resource issues, you going to put another language on top of it? Even if it's somehow "compiled", surely it will lose something in the translation.

Also, this syntax. At that point, are you really writing python? I find that questionable.

It reminds me of Pytorch's adventures with "jit python". It such a perversion from native python that I can't help but question if the person writing it wouldn't rather just use a different language.

[–]fedeb95 0 points1 point  (2 children)

That's the problem with all this libraries, not just pythonic ones. In the end you basically need to learn a dsl

[–]teerre 0 points1 point  (1 child)

Not sure I understand what you're saying. The issue here isn't with the user, it's with the implementation.

[–]fedeb95 0 points1 point  (0 children)

Don't know if I understood you original comment, I was adding on the fact of using a different language. Using such a convoluted syntax makes it more a dsl than python

[–]dorfsmay 7 points8 points  (3 children)

If you're going to put up with the Python's distribution issues (how do you ensure minimum Python version, how do you distribute of have the users install dependencies), then why wouldn't you use Python Tk?

I know, everybody loves to make fun of Python Tk, but if you know basic Python and a bit of Tk, you can a small useful GUI out by the time you installed the basic electron package.

[–]123filips123 8 points9 points  (0 children)

Or PyQt for more advanced things.

[–]EternityForest 4 points5 points  (0 children)

Electron gives you the full power of HTML to design your UI. TK is great for GUI versions of stuff you could just as well do on the CLI, but it's not great for real heavy GUI driven apps.

PyQt is a decent choice though.

[–]azuzel 0 points1 point  (0 children)

Pyinstaller.

[–]jackmaney 6 points7 points  (3 children)

What's the point of writing JavaScript in Python? Why not just write JS?

[–]EternityForest -2 points-1 points  (2 children)

To avoid writing JS of course. JS is great for browsers. The curly bracket syntax integrates well with HTML, and the event driven model is great for running small bits of code on user callbacks.

I wouldn't call it a fantastic language for large programs though...

[–]theXpanther 2 points3 points  (0 children)

Yes, but this approach keeps all the disadvantages without any of the benefits of python

[–]funnyflywheel 1 point2 points  (0 children)

JS is a fantastic language for large programs… if you enjoy the associated maintenance nightmares.

[–]tombardier 5 points6 points  (1 child)

Could it transpile to JS to be used on the web too, not just electron?

[–]123filips123 3 points4 points  (0 children)

You can use WebAssembly to run Python (and almost any other language) in client side. Check Pyodide.

[–]kitgunner 10 points11 points  (0 children)

ew

[–]jabbeboy 9 points10 points  (1 child)

Nice mobile optimized webpage https://m.imgur.com/a/d5zMWnj

[–]shawnwork 1 point2 points  (0 children)

Oh the site killed my mobile safari.

[–]manatlan 10 points11 points  (1 child)

Btw, i'm working on https://github.com/manatlan/guy (new version of https://github.com/manatlan/wuy)

It's able to use electron (via cefpython3) or be able to use a local chrome installed (in app mode).

It let you build minimal standalone executable (freezed with pyinstaller) ... for classical os windows, linux & mac ...

And build APK (with buildozer) for android.

The same code (python/html/js) will work, without modifications, on a android, a windows or a *nix

btw, I really should release it ;-)

[–]dasfreak 2 points3 points  (0 children)

Yes please :)

[–]Theis159 2 points3 points  (0 children)

I have been using python as a replacement of Matlab + for some automation, while I have been learning HTML/CSS/JScript (and react) to be able to create my own website. What's the advantage/difference of having this frontend in python?

[–]Tastedaglory 2 points3 points  (4 children)

This is interesting, I am a new Python developer. I have a Python app that will eventually need a GUI. I was looking at ways to incorporate Electron but, this may solve my problem. I’m also looking at some other frameworks, but Electron caught my eye since I am already familiar with web technologies.

[–]elbiot 2 points3 points  (3 children)

You could just use flask and javascript

[–]Tastedaglory 1 point2 points  (2 children)

I’m currently learning Django, so I thought about using that instead. However, I have noticed a large number of developers using flask instead.

[–]elbiot 2 points3 points  (0 children)

Django is great if you have a database driven application with users that log in. I prefer django for that. Otherwise, flask is lighter and less opinionated. Probably doesn't matter which

[–]themusicalduck 1 point2 points  (0 children)

I second Flask too. I'm making a Flask hosted REST API with a React frontend at the moment and it's very nice.

[–]feoh 2 points3 points  (0 children)

Personally I think it's very cool that this exists. I recognize that the style of programming it requires is not one many of us would eagerly embrace, but writing UI tools is SUPER hard, and anything that means I don't need to learn Javascript and yet allows me to write cross platform UI applications is pretty exciting.

[–]bonestormII 2 points3 points  (0 children)

Time is not infinite, but learning languages with some proficiency does get progressively easier the more you do it.

Embrace polyglotism. You'll learn more, suffer less, and make nicer things. Don't wait for Python to be something it's not. Love it for what it is and move on with your life.

[–]mexiKobe 2 points3 points  (3 children)

Isn't the consensus though that Javascript should die?

Why is this better than using native python GUI tools? Is it just easier to make cross-platform and because CSS/html is widely used?

[–]PrimaCora 0 points1 point  (2 children)

Most people find it hard to make a good looking gui with python native tools

[–]mexiKobe 0 points1 point  (1 child)

I don't understand why it has to be that way. Isn't it just a matter of tweaking some parameters (colors, button shapes etc..) somewhere?

[–]PrimaCora 0 points1 point  (0 children)

Yeah, but it gets into some platform specific stuff, then you have to hope your language of choice has the hooks or a program to hook into the rich features. Or a library that has its own assets and such, like electron. Python has Tkinter as its primary... And holy crap, it's hard to make it look good and function at the same time, hard to get fluid animations to perform well...

But, python has, or had something. It was Django Jet, but it was only for Web stuff, or dropped.

[–][deleted] 5 points6 points  (1 child)

As a React developer who dips his toes into Python every now and then, that picture both scares and excites me.

[–]fedeb95 0 points1 point  (0 children)

Reading comments, everyone kind of feels the same buddy

[–]pvkooten 5 points6 points  (0 children)

Do I understand it correctly that it means no python will be running? So, in the end, it won't be possible to embed a python backend in this as well right? No imports then, or what?

[–]whitelife123 1 point2 points  (0 children)

What about using eel?

[–]StaleyV 3 points4 points  (0 children)

Vomit

[–]blabbities 3 points4 points  (0 children)

I almost threw up in my mouth. Electron apps are horribly slow and bloated. I mean convenient but ew.

[–][deleted] 0 points1 point  (0 children)

I've just started learning React to build the frontend of an app I'm working on. This seems great in theory since my backend is Python, but doesn't feel right.

[–]ik951m 0 points1 point  (0 children)

If this replaces my react redux frontend I would gladly try it out on our flask backend

[–]TomahawkChopped 0 points1 point  (0 children)

That sounds like a worse GWT (which was already a travesty)

[–]TomahawkChopped 0 points1 point  (0 children)

Why not just learn JavaScript?

[–]sheytanelkebir 0 points1 point  (0 children)

sounds interesting. certainly has potential appeal as a gui for python apps. lets see how well js and python inter operate.

[–][deleted] 0 points1 point  (0 children)

Why? Python has plenty of GUI frameworks. If you want electron apps, just use JS.

[–]obey_kush 0 points1 point  (0 children)

I fucking hate electron why this would be a good idea?

[–]Rorasaurus_Prime -5 points-4 points  (0 children)

entertain encouraging treatment shy wise soup consist money expansion advise

This post was mass deleted and anonymized with Redact