How To Use Both Kivy and GTK in the Same Application

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:

There is a mobile optimized version of this page, view mobile Version.

Leave a Reply