How to get rid of the background gradient of the inline GtkToolbar?

Solution 1:

Here we go:

example screenshot

First you need to find the default background color for the the current theme. Then you can inject it into the current css for the GtkToolbar class.

# Get the default window background color for the the current theme.
win_style_context = window.get_style_context()
bg = win_style_context.lookup_color('theme_bg_color')[1].to_string()

# Then we set that as the background for GtkToolbar
# We also make the boarder transparent
css_provider = Gtk.CssProvider()
toolbar_css = ".inline-toolbar.toolbar { background: %s; border-color: transparent; }" % (bg)
css_provider.load_from_data(toolbar_css.encode('UTF-8'))
screen = Gdk.Screen.get_default()
win_style_context.add_provider_for_screen(screen, css_provider,
                                          Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

Note that you need to from gi.repository import Gdk