Ubuntu – How to change GtkWidget background in GTK3

application-developmentgtk3python

I'm trying to use override_background_color on some GTK3 widgets but they still showing up with the default background color.

Best Answer

GTK+ 1.2

  GtkRcStyle *rc_style;
  GdkColor color;

  color.red = 65535;
  color.green = 0;
  color.blue = 0;

  rc_style = gtk_rc_style_new();

  rc_style->bg[GTK_STATE_NORMAL] = color;

  rc_style->color_flags[GTK_STATE_NORMAL] |= GTK_RC_BG;

  gtk_widget_modify_style (widget, rc_style);

  gtk_rc_style_unref (rc_style);

GTK+ 2.24

Using the GDK Library:

GtkWidget *widget; //your widget

  GdkColor color; 

  gdk_color_parse ("red", &color); //setting a color - you can also use RGB

  gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color); //modifying the background color of the widget

Full reference about GdkColor can be found at GNOME'S Dev Documentation.

GTK 3.0

For gtk+3 you can use gtk_css_provider() .Full tutorials and examples can be found at the GTK+ Forums.