0

I am using : "gtk+-bundle_2.24.10-20120208_win32" in MinGW using gcc on windows 7...

I have difficulty to set color in the button .. my code is

GdkColor color;
gdk_color_parse ("red", &color);
gtk_widget_modify_bg ( GTK_WIDGET(a3), GTK_STATE_NORMAL, &color);
gtk_widget_show_all(window);

But I cant get the button with color red... What to do ..

liberforce
  • 11,189
  • 37
  • 48
681ankit
  • 3
  • 1
  • 5
  • Do you add your wiget, before "show all"? eg. `gtk_container_add(GTK_CONTAINER(window), button);` Is this example working for you: http://stackoverflow.com/questions/99488/how-do-i-change-the-colors-of-an-arbitrary-widget-in-gtk ? – pce Nov 09 '12 at 11:31
  • I tried that but not working also – 681ankit Nov 09 '12 at 11:44

3 Answers3

2

This works with GTK 2 on Linux:

#include <gtk/gtk.h>

int main (int argc,char **argv)
{
    GtkWidget *button;
    GtkWidget *window;

    gtk_init (&argc,&argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (G_OBJECT(window), "destroy",
            G_CALLBACK (gtk_main_quit), NULL);

    button = gtk_button_new_with_label ("Hello World !");
    gtk_container_add (GTK_CONTAINER (window), button);

    GdkColor color;
    gdk_color_parse ("red", &color);
    gtk_widget_modify_bg (GTK_WIDGET(button), GTK_STATE_NORMAL, &color);

    gtk_widget_show_all (window);
    gtk_main ();

    return 0;
}

Compile it and check it works on your platform.

liberforce
  • 11,189
  • 37
  • 48
  • ..I tried it but still the color of button is not set..I think it will not work in windows – 681ankit Nov 10 '12 at 04:31
  • Check that it is not being overridden in a gtkrc file, if the rc file is setting the bg_color of the button widget, it will override manually setting them in the code. – technosaurus Nov 19 '12 at 22:22
2

I used the event box in gtk2.24.10, it works.

I found this on the net.

"modify_bg() only affects widgets that have an associated gtk.gdk.Window.

Widgets that do not have an associated window include:

gtk.Arrow,gtk.Bin, gtk.Box, gtk.Button, gtk.CheckButton, gtk.Fixed , gtk.Image ,gtk.Label , gtk.MenuItem , gtk.Notebook , gtk.Paned , gtk.RadioButton , gtk.Range , gtk.ScrolledWindow , gtk.Separator , gtk.Table , gtk.Toolbar ,gtk.AspectFrame , gtk.Frame , gtk.VBox , gtk.HBox , gtk.VSeparator ,gtk.HSeparator.

These widgets can be added to a gtk.EventBox to overcome this limitation."

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
-1

Installing Gtk

To install the Gtk libraries we can visit the following link. Scroll down to the middle of the page and you will find the All-in-one bundles. Downloading installs the runtime library and developer versions.

http://www.gtk.org/download/win32.php

Run the installer and install to the default location, C:\Program Files (x86)\GTK2-Runtime\, and proceed to append the Path environment variable with the binary and library files: C:\Program Files (x86)\GTK2-Runtime\bin; C:\gtk\bin; C:\gtk\lib; C:\gtk\include;

Button Fix

It is recommended to rename the share directory in the GTK2-Runtime directory. The default directory is C:\Program Files (x86)\GTK2-Runtime\. I renamed the share directory to _share and all of the color code for widgets now works great!

There are gtkrc files that store the GUI properties of all of the Gtk widgets. If this directory is not renamed, moved, or deleted then all of the styles of the ATST GUI will appear to be the default set by the runtime or grey.

Wouter J
  • 41,455
  • 15
  • 107
  • 112
mikeppalmer
  • 41
  • 2
  • 7