I have been doing this for several days, but I just canβt understand what could be.
Essentially, I'm trying to create some Gtk widgets in Gtk3 using CSS style declarations, nothing complicated, but just trying to customize the target element by its id / name. Gtk documentation for Gtk.CssProvider () says that
#widgetname { background-color: #333333; }
should work as a valid selector for the widget with its name set to "widgetname", but I just can't get it to work. Initially, I thought CSS was not loading, but I can target top-level widgets:
GtkWindow { background-color: #333; }
and it will apply style to the window, and I see that the background color has changed. I tried using this name as an identifier for several different types of widgets (GtkEventBox, GtkTextView, GtkStatusBar, GtkBox), and the ID-based selector just doesn't work.
Here is a shortened snippet of how I load css:
css = Gtk.CssProvider() # css.load_from_file(file) css.load_from_data(''' GtkWindow { background-color: #333; } GtkEventBox { background-color: #333; } #statusbarwrap, #textview_event_wrap, #box1 { background-color: #333; } ''') style_context = self.get_style_context() style_context.add_provider( css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
Here are the docs for GtkCssProvider https://developer.gnome.org/gtk3/3.7/GtkCssProvider.html
Example 24 on this page (just scroll down the page or page) shows that the #ID selector is valid, and I'm setting the name for the widgets in Glade.
Any help would be greatly appreciated.