Today I was wondering whether both Kivy and GTK could run together in the same application. So I started looking up online to see if anybody already tried, but I didn’t find anything. Then I thought maybe I could try doing it myself. I was surprised when I managed to do it. All you need to do is run them in a separate thread. That’s it! I thought it wasn’t going to work as GTK is very picky with threads, but it did!
You can do very useful things with both frameworks running. You can, for example, have an Ubuntu AppIndicator connected to your app, create a Unity launcher QuickList, use the music/messaging menu, send notifications, run a separate GTK window, etc.But I’ll let you do that yourself. This is my hybrid “hello world” application that uses both GTK and Kivy
As you can see it’s very simple. The two threads can interact with each other (Kivy is more flexible though, which is why I use it 😉 ). Note that the whole Python process will stay up until both the threads are done running: it means that if you close the Kivy window, the GTK one will continue to stay up, and vice versa. If you want to kill the GTK window when you close Kivy’s, you need to set the daemon attribute of the thread to True. This will however kill the thread abruptly.
I didn’t try these, but I made a list of some resources that might help you integrate Kivy with Ubuntu/GNOME using GTK:
- Read The Docs – The Python GTK+3 Tutorial
- GNOME Developer – GTK+3 Reference Manual
- PyGTK 2.0 Reference Manual (if you want to use the older deprecated PyGTK instead of the more complicated GTK+3)
- Ask Ubuntu – How to add support for the global menu to a python non-gtk, non-qt app?
- WayBack Machine – Dbusmenu 0.4 Python API documentation (from the old developer.ubuntu.com)
- WayBack Machine – AppIndicator (from the old developer.ubuntu.com)
- Launchpad – Unity Integration Showcase (hello-unity)