When you run the below code, it will show an inline toolbar in a window. Notice how the inline toolbar has a stand-out backbround. Is there a way to apply CSS to get rid of it and make blend with regular window color?

from gi.repository import Gtk

buttons = [Gtk.ToolButton.new_from_stock(name) for name in button_names]
toolbar = Gtk.Toolbar()
for button in buttons:
    toolbar.insert(button, -1)
style_context = toolbar.get_style_context()
grid = Gtk.Grid()
label = Gtk.Label()
window = Gtk.Window()
window.set_size_request(200, 50)
window.connect('delete-event', Gtk.main_quit)

Using andrewsomething code, it's starting to look better but the "border" is still there and takes up space. Notice in the below screenshot the toolbar on the left is smaller than the regular buttons on the right: ubiquity testing


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)
screen = Gdk.Screen.get_default()
win_style_context.add_provider_for_screen(screen, css_provider,

Note that you need to from gi.repository import Gdk

  • I will add it to ubiquity first & only then award bounty. – Dima Sep 12 '12 at 17:03
  • Can this be done for inline toolbar only? – Dima Sep 12 '12 at 18:28
  • You loose brownie points for not being pep8 nor python3 compliant – Dima Sep 12 '12 at 18:40
  • Updated for Python3. It should now only apply to inline toolbars. What's the pep8 issue? Line length? – andrewsomething Sep 12 '12 at 20:25
  • all good. now the issue is that the border is still there & still takes up space. Let me post a screenshot. – Dima Sep 13 '12 at 9:19

You can also use:

css_provider = Gtk.CssProvider()
toolbar_css = ".inline-toolbar { background: alpha (@base_color, 0.0); border-color: transparent; }"
win_style_context.add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.