Search code examples
pythonpython-3.xgtkgtk3gnome

Set spacing of Gtk3 HeaderBar in Python?


According to the official documentation (https://developer.gnome.org/gtk3/stable/GtkHeaderBar.html), GtkHeaderBar has a spacing property.

To change the subtitle and title properties in python you would use

headerbar.set_title()
headerbar.set_subtitle()

So it should therefore follow that spacing() would also follow the same rules, however I am informed of the following error

AttributeError: 'HeaderBar' object has no attribute 'set_spacing'

What is the reason for this? I have not been able to find any specific examples, the documentation is the only place that covers its use, and according to it spacing is clearly a property of GtkHeaderBar

Appreciate any help you can give here


Solution

  • To set GObject properties directly, each object has a props attribute:

    headerbar.props.spacing = 5
    headerbar.props.subtitle = 'Habits of the Algorithmic Mind'
    

    I believe this is so that when you mistype a property name it won't silently fail (e.g. headerbar.spaing = 5). Although other language bindings for GObject, such as JS and Ruby, treat GObject properties the same as attributes of the object.