Skip to content
Advertisement

PyGObject: How to create hamburger menu programmatically

I would like to create a “primary menu” programmatically, which I believe is also called a “hamburger menu”. I have done several of these while working on web development side, but I have never done these using Python and GTK. This topic seems to be controversial and there are a lot of different solutions out there. I would like to create a menu like this using the non-deprecated way.

In the documentation is mentioned that the old style menus are deprecated (the whole section is archived under “deprecated”): https://python-gtk-3-tutorial.readthedocs.io/en/latest/menus.html

In this example, the whole HeaderBar is made programmatically and a (popover) menu is added into it: GtkMenuButton popups

While that seems to do the trick, it’s not a “hamburger” menu and the documentation seems to suggest “Your menus should be defined in XML using Gio.Menu”: https://python-gtk-3-tutorial.readthedocs.io/en/latest/application.html#menus

So I am quite lost here. Can someone give me an example how to achieve this? Preferably done programmatically, but if the XML is the only way then so be it.

Thanks in advance!

Advertisement

Answer

I post my solution that I was able to do with the kind help from irc.gnome.org #python channel. It’s not perfect, menu actions are still not working, but at least I got the menu done which was the point of this post.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement