Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
Can you post the code that you used in the end? – Mendhak Jul 7 '12 at 21:24
I"ve dropped it because I didn't have the time. Will try it later. – int_ua Jul 8 '12 at 8:54
I managed to do it here by using CSS in the GTK3 widget. – Mendhak Jul 22 '12 at 7:51
up vote 2 down vote accepted

GTK+ 1.2

  GtkRcStyle *rc_style;
  GdkColor color; = 65535; = 0; = 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.

share|improve this answer
I've tried it first but in python there was no gdk.color_parse() function IIRC. Let me re-check... – int_ua Jun 29 '12 at 13:47
i am not familiar with pygtk but you can take a look here – Rrjrjtlokrthjji Jun 29 '12 at 13:52
besides: Warning gtk_widget_modify_bg has been deprecated since version 3.0 and should not be used in newly-written code. Use gtk_widget_override_background_color() instead – int_ua Jun 29 '12 at 13:54
im still using GTK+ 2.24.Can you edit your post with the code which you use to change the background color?that would help – Rrjrjtlokrthjji Jun 29 '12 at 13:57
In python you can do something like: [your widget].override_background_color(Gtk.StateFlags.NORMAL,Gdk.RGBA(1.0,0.0,0.0,1))‌​ or [your widget].modify_bg(Gtk.StateFlags.NORMAL,Gdk.color_parse("red")) – AndAC Jun 29 '12 at 16:13

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.