Python desktop application development - Therry van Neerven

Tags: python

(Summary of a talk at a python meeting in Eindhoven, NL. I also gave a presentation (just the slides)).

He’s the author of the “sendcloud client”, a desktop app of the company he works for. It steers a barcode scanner and prints out packaging slips.

Why a desktop app? They wanted to make it look like a native windows app. But especially, they wanted to do two things that a browser app cannot do: printing without a dialog and scanning barcodes! So they needed to.

Why in python? He wanted to learn more about python. And python allowed him to work quickly. There are quite a lot of libraries that helped him a lot (examples: requests, pywin32, pyusb).

There are a couple of GUI frameworks for python. Some don’t look too good, others are nicer. Kivy is a nice one. As is PyQt/PySide. PyQt might mean some licensing costs. Kivy has less features and it is not native looking. Kivy does have a more innovative UI as it is build on PyGame. It also supports android and ios.

Tip by Therry: if you’re interested, simply get your hands dirty. Try out something!

Important for desktop applications is to “freeze” your application. “Freezing” means compiling your python scripts to bytecode and to put them in a zip folder. The zip gets appended to a python interpreter. Then you place the pyhton interpreter in a folder where it can find all the other dependencies like Qt and your funny kitten images.

You can tool it and in the end, the process is quite accessible. You can look at CX_Freeze, Nuitka or Py2exe.

Freezing needs to happen on the platform where you want to build for. Cross platform building means you need to use virtual machines (vagrant, virtualbox, etc).

Script your build process as you will build your app very often.

Installers alre also important. Inno setup, NSIS and pynsist are options for windows. Shipping updates is simple: just create a new installer for every build… You could look at esky if you want to update without needing a completely new packages.

Some tips:

  • Pick the GUI framework that fits your needs. Do you need an elaborate one? Is a simple one fine?
  • Automate the things you do often. Makefiles of python scripts: both fine. It can save you hours of typing and clicking!
  • Not every GUI framework or package builder is mature. Feel free to discuss on github or stackoverflow.
  • You can make browser extensions. These might help you get the printing working that would normally not work well in a web environment. Suddenly you might be able to re-use all your web knowledge anyway!
  • From your webbrowser you could even connect to a desktop app with a REST API or a websocket. So you only have to build a desktop app that provides a little webserver and exposes it to your browser… Nice idea!
blog comments powered by Disqus logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):