Building Desktop Apps with Python
Published on#python #desktop #html #css #js
I’ve built something, and I’ll probably regret it later. You remember Electron? How can you forget, it’s everywhere, even in your text editor. So, I thought, I can build something similar for Python. Aaaand, here we are. I present you, Positron.
Before you say anything, let me clarify some things. First, this is not a framework; it’s simply a way to package your Python applications as desktop apps. Second, it’s not a replacement for Electron, it’s not cross-platform, it’s only for Linux. Third, I know you can also run Python apps with Electron. And lastly, it might be inefficient as hell, but it has worked fine for me, so far.
About Positron
So, what is Positron? Positron is a way to build desktop applications on Linux with Python, where you can develop your frontend with HTML, CSS, and JavaScript. It uses the Firefox browser to render the content, while serving the files and routes with Quart, a Python web microframework based on Flask, but with async capabilities.
Packaging the app is done with Flatpak, which works really well in my opinion. It’s available for most Linux distributions if not all, and it’s easy to install and use. Besides, it’s a great way to distribute your apps built with Positron on FlatHub.
Why did I build it?
This question is always hard to answer. I’d simply say, because I thought it should be possible to build it. But perhaps, the real reason might be that the current solutions for building graphical desktop applications with Python were not satisfying for me, as either they were too old and unpleasant to look at, or they were too complex to work with. Why should I try to build something with them if I don’t feel any joy in the process? So, I built this whacky thing, and I feel good about it.
Can it …?
Probably, yes, and no. It can do a lot of things, it can’t do a lot of things. There are still things that I should improve, such as making the build size smaller, or making the app more performant. So far, I’ve tried creating a music player with it, and it worked quite well. I’m sure it can handle more complex applications, but there would be a point where you’d say, “Why am I even building graphical desktop applications for Linux, and with Python?”. I hope you’ll reach that point before I do.
About the name
I’m not good at naming things, they come all plain and boring. The name actually came to me from Asimov’s Robot series. Robots in the series are powered by their positronic brains, which I thought was a cool name for this project. And, since there’s Electron, why not Positron?
What’s next?
Give it a try, and let me know what we can improve. I’ve also created a documentary with some topics that might be helpful for you to get started. You can find the repository below. Thanks for reading! And have fun!
kaangiray26What was I thinking? People will probably curse it for the ~270MB build size. But hey, positrons have the same mass as electrons, so it's fine, right? 😅