http://blog.csdn.net/oLanMoMo/article/details/14453447
#include <gtk/gtk.h>
//GdkRGBA rgba_color; //gtk3.0
GdkColor rgb_color; //gtk2.0
typedef GtkWidget *PGtkWidget;
int main (int argc, char* argv[])
{
PGtkWidget window, button, vbox;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
button = gtk_button_new_with_label("Hello world!");
//背景色设定
//gdk_color_parse("blue", &rgb_color); //gtk2.0
//gdk_rgba_parse(&rgba_color, "blue"); //gtk3.0
//gtk_widget_modify_bg(button, GTK_STATE_NORMAL, &rgb_color);//gtk2.0
//gtk_widget_override_background_color(button, GTK_STATE_NORMAL, &rgba_color);//gtk3.0
//前景色设定
gdk_color_parse("red", &rgb_color);//gtk2.0
//gdk_rgba_parse(&rgba_color, "blue"); //gtk3.0
gtk_widget_modify_fg(button, GTK_STATE_NORMAL, &rgb_color);//gtk2.0
//gtk_widget_override_color(button, GTK_STATE_NORMAL, &rgba_color);//gtk3.0
vbox = gtk_vbox_new(TRUE, 0);//gtk2.0
//vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);//gtk3.0
gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
g_signal_connect(window, "delete_event", gtk_main_quit, NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
终端里输入:
gcc -Wall -o color_button color_button.c $gtk2
其中gtk2是我为了方便而自定义的一个环境变量,具体内容大家懂的,不废话。