pygobjectgtk4

gtk_window_set_titlebar() is not supported for AdwApplicationWindow


Trying to make a GTK 4 app with Adwaita on Python on Windows.

Here are my imports:

import gi

gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw

So, here are the first few lines of my application window class.

class AppWindow(Adw.ApplicationWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.set_default_size(500, 400)
        self.set_resizable(False)

        header = Adw.HeaderBar()
        self.set_titlebar(header)

It gives an error about me using gtk_window_set_titlebar. I assume it's due to the fact that I'm using PyGObject which, despite sort of having documentation for Adwaita (most pages empty, which for some reason didn't look like a red flag to me), doesn't actually support it.


Solution

  • Yes, there is support, you are just using the wrong method. See the Adw.ApplicationWindow documentation. Try this:

    class AppWindow(Adw.ApplicationWindow):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
    
            self.set_default_size(500, 400)
            self.set_resizable(False)
    
            header = Adw.HeaderBar()
            box = Gtk.Box.new(1, 0)
            box.append(header)
            self.set_content(box)