2

Me and my teammates want to start a Python code base involving custom graphical user interface (GUI) applications that can be easily deployed internally and even distributed externally to customers. I expected this task to be trivial in 2020, but I seem to hit dead-ends/major issues every path that I explore. So after spending countless hours in research and unsuccessful problem solving, I decided to summarize my goal and ask the community. I am sure the solution would benefit many.

NOTE: I am not seeking "recommendations" but factual solutions that are known (based on experience) to meet the specific requirements below.

Goal

Find a GUI toolkit solution for Python 3 with the following requirements:

  1. License: Free, for development and light commercial distribution.

  2. Portability: Portable and easy to deploy on Windows 10, but also Mac OS X and Raspberry Pi (and maybe some mobile experiments).

  3. 2D Graphics: It must offer a way to present and update 2D graphics in semi-realtime (like updating the data of a matplotlib FigureCanvas multiple times per second).

  4. UI Design: A visual designer application must be available to design and update the GUI interface definition (in a text file that can be loaded by the Python code).

  5. UI Styling: It must offer an easy way to completely restyle the visual elements, ideally in a CSS-like manner (like adjusting the corner radius of buttons, colors, shadows or create a custom theme).

Attempts explored so far

Attempt 1: tkinter.ttk (TCL/Tk engine)

  1. [OK] Free

  2. [OK] Already part of Python 3 distribution

  3. [OK] FigureCanvasTkAgg

  4. [OK] pygubu-designer application, along with pygubu.Builder loader.

  5. [NOT OK] While ttk offers some color styling (ttk creating and using a custom theme, Python Tkinter custom themes), and predefined themes, I have not found any way to restyle the controls (i.e. adjust the roundness and shading of a button). See below.

Styling problems with tkinter.ttk

  • I can mimic the element structure of the 'clam' ttk theme button for instance (Create custom ttk style same as 'clam' ttk Theme (button widget specific)), but not reproduce the actual look/rendering of the button in python (corner roundness, gradient, etc.).

  • Using bitmaps or drawing raw shapes on a canvas are not acceptable solutions (Rounded button tkinter python)

  • EDIT: By inspecting the source code of some nice ttk themes, it reveals that shading and round button effects are all performed using bitmaps, which greatly increase the complexity of styling. BTW, the TCL script of the theme is actually interpreted (live) behind the Python tkinter module.

Attempt 2: PyGOjbect (GTK 3 engine)

  1. [OK] Free

  2. [NOT OK] I have not found a way to deploy on Windows 10 easily. See below.

  3. [OK] FigureCanvasGTK3Agg

  4. [OK] Glade (designer application saving .glade XML files) and Gtk.Builder (layout loader in Python).

  5. [OK] Gtk.CssProvider allows full customization using CSS-Like syntax.

Deployment problems with PyGObject on Windows 10

Attempt 3: wxPython (wxWidgets engine)

  1. [OK] Free
  2. [OK] Standard Python multi-platform package
  3. [OK] FigureCanvasWxAgg
  4. [WARN] something like wxGlade with wxGlue could work, but not widely adopted/maintained
  5. [NOT OK] wxWidgets seems to focus on "native" controls (Python - Custom styling in wxPython)

Attempt 4: PySide2 (Qt engine)

  1. [NOT OK] Not free. Qt commercial license is $4k/developer if funding >$250k.

  2. [OK] Can be deployed on Windows 10 and many other platforms

  3. [OK] FigureCanvasQTAgg

  4. [OK] Qt-Designer application and Python QUiLoader

  5. [OK] Qt Style Sheets (QSS)

Attempt 5: Web Rendering Engine

  1. [OK] I could explore many free options to create desktop-like applications using web technologies, such as REMI, PyWebView, eel, Flexx, Dash, etc.

  2. [OK] These options are generally standard Python packages

  3. [WARN] However to update a matplotlib plot usually involves refreshing an IMG source bitmap, which might not be optimal for high refresh rates

  4. [WARN] I could probably use a standard HTML/Web visual designer, but would need adaptation to Python module.

  5. [OK] HTML output would support all common CSS styling options.

Concerns with web rendering engines

  • I havent explored this option far enough yet.
  • Maybe the matplotlib refresh issue could be overcome with a JS plotting alternative such as plot.ly.
  • But I feel the level of complexity is increasing far beyond expectations. Is this my only option?

EDIT: Attempt 6: Kivy

  1. [OK] Free (MIT License)
  2. [OK] Standard Python multi-platform package, and buildozer to create application packages.
  3. [OK] FigureCanvasKivyAgg (pip install kivy-garden, then garden install matplotlib)
  4. [NOT OK] kivy-designer is DEPRECATED and no alternative found.
  5. [OK] kv-lang style definition

Is there any elegant solution to this technical challenge, meeting all 5 requirements?

Thanks

BinaryMonkey
  • 331
  • 1
  • 13
  • 1
    I'm sure there are at least two or three ways to do what you want, but asking for library recommendations is off topic here. I know you say you aren't seeking recommendations, but clearly you are. – Bryan Oakley May 02 '20 at 22:25
  • FWIW, _"Understanding that tkinter.ttk is a wrapper around a native library (TCL/Tk 8.6), I am afraid that only TCL code might allow full control on styling."_ is not true. Anything you can do with styling in Tcl you can do in Python. – Bryan Oakley May 02 '20 at 22:27
  • Thanks @BryanOakley for helping me solve the technical issues I encountered. Looking at the list of ttk themes (https://wiki.tcl-lang.org/page/List+of+ttk+Themes), would that mean that I could, in Python, achieve the gradient of the 'blue' theme button and the slider look of the 'clearlooks' theme? I failed to find any resources on this topic. – BinaryMonkey May 03 '20 at 02:58
  • tkdocs.com has some documentation on themes. – Bryan Oakley May 03 '20 at 03:35
  • 1
    Have you tried **kivy?** – droptop May 03 '20 at 09:34
  • @BryanOakley, tkdocs.com mention that "aqua" theme will only run on macOS which let me believe that theme definitions were using system calls that are not available in Python. I will try to download the source code of some themes to understand how it really works. – BinaryMonkey May 03 '20 at 22:07
  • @droptop, I have not tried Kivy yet. Do you know if it meets the 5 requirements above? – BinaryMonkey May 03 '20 at 22:09
  • @BinaryMonkey it does. You can even run your kivy app on android and ios using `buildozer`. And for 4th requirement, there's `kv-lang` that's similar to css and electron – droptop May 03 '20 at 22:37
  • Yes, some of the themes use native controls. The default theme on OSX uses OSX controls. the default theme on windows uses Windows controls. – Bryan Oakley May 03 '20 at 22:58
  • @droptop, I had a look a Kivy, which I find attractive, but unfortunately could not find a viable UI designer (requirement #4). – BinaryMonkey May 06 '20 at 03:47
  • @BinaryMonkey it's easy to do the UI using entirely kv-lang and no python – droptop May 06 '20 at 09:29
  • With regard to PySide2, this article says it can be used under LGPL: https://www.learnpyqt.com/blog/pyqt5-vs-pyside2/ In the Anaconda distribution, it is available (PySide2) for all platforms. https://www.learnpyqt.com/blog/pyqt5-vs-pyside2/ Or am I missing something here? I don't know if there is a restriction on using Qt Designer, but you use a pyside2-uic program to convert it to something else, you are using PySide2, not the Qt libraries: https://www.badprog.com/python-3-pyside2-setting-up-and-using-qt-designer - You'd still have to comply with LGPL, though. – asylumax May 19 '20 at 00:46
  • Additionally, this link sheds some light: https://opensource.stackexchange.com/questions/9470/can-i-sell-a-proprietary-software-with-an-lgpl-library-bundled-along-with-it-wi – asylumax May 19 '20 at 15:26

1 Answers1

0

If #5 is an absolute requirement, go for PyQt. The learning curve is steep, though, and the development model is not very comfortable (no matter whether you use traditional Qt Widgets - with or without Qt Designer - or the more recent touch oriented QML).

Otherwise drop requirement #5 and go for wxPython with wxGlade. Your life will be much easier. wxGlade even includes matplotlib examples to get you started.

I have not yet seen a desktop application with a customized GUI where the effort was worth it. Often, such customized looks go hand in hand with messed up usage.

  • Thanks for your feedback, but Qt is not free when funding > $250k, which is a dealbreaker. As for wxPython, I don't want to create apps that looks like boring windows forms. For some applications, I might want rounded buttons like modern web apps (think Material Design). For other applications, I might want to create a dark dashboard with cool graphics. I am just surprised that in 2020, the community has yet to come with a powerful & free solution for modern GUI design. – BinaryMonkey Jul 14 '20 at 03:22