Rumah > Artikel > hujung hadapan web > GTK3.0 使用CSS设置控件背景色_html/css_WEB-ITnose
/* Compile with: gcc -Wall -o backimage `pkg-config --cflags --libs gtk+-3.0` backimage.c */#include <gtk>int main(int argc, char *argv[]){ GtkWidget *window;/*----- CSS ----------- */ GtkCssProvider *provider; GdkDisplay *display; GdkScreen *screen;/*-----------------------*/ gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);/* gtk_window_set_default_size (GTK_WINDOW(window), 500, 300);*/ g_signal_connect (GTK_WIDGET(window), "destroy", G_CALLBACK (gtk_main_quit), NULL);/*------------- CSS --------------------------------------------------------------------------------------------------*/ provider = gtk_css_provider_new (); display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER); gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider), " GtkWindow {\n" " background-image: url('abstract-blue-02.jpg');\n" "}\n", -1, NULL); g_object_unref (provider);/*----------------------------------------------------------------------------------------------------------------------*/ gtk_widget_show_all (window); gtk_main ();return(0);}</gtk>
apt-get install gtk3.0
参考资料:
http://www.gtkforums.com/viewtopic.php?f=3&t=988&sid=b63d18d182917efd7e2b04eb8c5e50c1&start=15