Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Is it possible to use gradient as a background for generic GtkWidget?

Related question: How to change GtkWidget background in GTK3?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Sure you can!

ugly gradient widget

Gtk3 allows for theming using CSS. Here's a quick example I threw together in Python:

from gi.repository import Gtk, Gdk

button = Gtk.Button("Click Me")
grid = Gtk.Grid()
window = Gtk.Window()
window.set_size_request(200, 50)

css_provider = Gtk.CssProvider()
css = """
 .button {
      background-image: -gtk-gradient (linear,
                                       left top,
       left bottom,
       from (#d0e4f7),
       color-stop (0.5, darker (#d0e4f7)),
       to (#fdffff));

screen = Gdk.Screen.get_default()
style_context = window.get_style_context()
style_context.add_provider_for_screen(screen, css_provider,

window.connect('delete-event', Gtk.main_quit)

Carlos Garnacho has a great article on GNOME Journal that gets into the specifics.

share|improve this answer
It seems that older versions of GTK paint only children widgets. I've not found a reliable way to color the area of a widget. –  ThorSummoner Sep 11 at 5:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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