Using gtk3, how can I change the default GtkWindow titlebar color? Would it involve GtkStyleContext? I've only used GtkCssProvider.
gtk3 GtkWindow title bar color
3.7k Views Asked by mike At
2
There are 2 best solutions below
0

You can do it... ( at least on Linux ) What happens is that your window is being un-decorated then "decorated" with a header bar ( which happens to have a bloody "show_close_button", so I guess this is an intended use )
class base_ui(Gtk.Window):
def __init__(self):
# initializing self ( the window )
Gtk.Window.__init__(self, title="window title")
self.set_border_width(1)
self.set_default_size(800, 600)
# Create the header bar
hb = Gtk.HeaderBar()
# This is the id of the header bar to be used in the css file
hb.set_name("mw_hb")
# we can even set a close button ...
# you can add the other buttons as well, but have to do it yourself
hb.set_show_close_button(True)
# the effective text in the titlebar ( the window title )
# is props.title
hb.props.title = "win title"
# and here comes the sun - we set our headerbar as the new titlebar.
# Bazinga
self.set_titlebar(hb)
You can't change the titlebar color from GTK. The titlebar is drawn by the window manager, and GTK doesn't "know" anything about it. You can only communicate with the window manager through "hints", such as whether the window should have a titlebar or what string should be displayed there, but the window manager is free to ignore them.