0

is posible change the background color of an object GtkBox? so far all the styles I have worked well in other objects but GtkBox not work for me You know why? this is my code

self.Ventana = self.builder.get_object("ventana")
self.Header= self.builder.get_object("header")
self.Ventana.set_name('MyWindow')
self.Header.set_name('header')
self.style_provider = Gtk.CssProvider()
self.css=open(self.ruta+'/css/estilos.css','rb')
self.css_data = self.css.read()
self.style_provider.load_from_data(self.css_data)
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),self.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

/*********CSS STYLES *********/
#MyWindow {
    background-color: #1d1d1d;
}
/*i try whit: #MyWindow #header, #MyWindow GtkBox */
#header{
    background-color: #ffffff;
    border-bottom: 1px solid white;
}

1 Answer 1

1

The problem is that not all gtk widgets draw their own background. The background is then determined by the underlying widget. This behavior was changed for some widgets with gtk+ 3.12.

So changing the background color of a Gtk.Box does not work for version < gtk+ 3.12. If you are using an older version, an alternative approach would be to use a Gtk.Viewport underneath the Gtk.Box and change the color of the viewport.

To put it into some code:

box = Gtk.Box()
viewport = Gtk.Viewport()
viewport.add(box)
#and the CssProvder, StyleContext,...

CSS:

GtkViewport {
    background-color: red;
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.