GTK改变窗口的背景图像 [英] GTK changing background image of window
问题描述
我找到了一个适用于我的python示例:
http://islascruz.org/html/index.php/blog/show/Image-as-background-in-a-Gtk-Application..html p>
代码
#!/ usr / bin / env python
import gtk
def draw_pixbuf(widget,event):
path ='/home/markuz/wallpapers/WMwall1024x768.gif'
pixbuf = gtk.gdk.pixbuf_new_from_file(path)
widget.window.draw_pixbuf(widget.style.bg_gc [gtk.STATE_NORMAL],pixbuf,0,0,0,0)
window = gtk .Window()
window.set_title('Drawing Test')
window.set_size_request(640,480)
window.connect('destroy',gtk.main_quit)
hbbox = gtk .HButtonBox()
window.add(hbbox)
hbbox。 connect('expose-event',draw_pixbuf)
button = gtk.Button('Press Me!')
hbbox.pack_start(button,True,False,10)
window.show_all )
gtk.main()
我还在:
http:// www .gtkforums.com / viewtopic.php?t = 446
代码
GtkWidget * SetupWindow(gchar * data,gboolean Transient)
{
GdkPixmap * background;
GdkPixbuf * pixbuf;
GdkScreen *我们的屏幕;
GdkColormap * colormap;
GtkStyle *风格;
GdkColor fg;
GdkColor bg;
GError * error = NULL;
GdkRectangle * rect;
GtkWidget *窗口;
pixbuf = gdk_pixbuf_new_from_file(pics / fb.png,& error);
if(error!= NULL){
if(error-> domain == GDK_PIXBUF_ERROR){
g_print(Pixbuf相关错误:\\\
);
if(error-> domain == G_FILE_ERROR){
g_print(File Error:Check file permissions and state:\\\
);
}
g_printerr(%s \ n,error [0] .message);
exit(1);
}
gdk_pixbuf_render_pixmap_and_mask(pixbuf,& background,NULL,0);
style = gtk_style_new();
style-> bg_pixmap [0] = background;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),data);
// gtk_window_maximize(GTK_WINDOW(window));
gtk_window_set_modal(GTK_WINDOW(window),TRUE);
gtk_window_set_default_size(GTK_WINDOW(window),640,480);
gtk_widget_set_style(GTK_WIDGET(window),GTK_STYLE(style));
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS);
gtk_container_set_border_width(GTK_CONTAINER(window),14);
if(Transient == TRUE)
gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(mainwindow));
gtk_widget_show(window);
return(window);
}
但我没有试过它。
how can I achieve it? I was searching for it for like 30 minutes and found examples which don't work or work in bad way. I simply want to change background image of window without changing bakgrounds of other dialogs windows etc? But I want buttons and labels to be transparent on that background.
I found a python example that worked for me at:
http://islascruz.org/html/index.php/blog/show/Image-as-background-in-a-Gtk-Application..html
Code
#!/usr/bin/env python
import gtk
def draw_pixbuf(widget, event):
path = '/home/markuz/wallpapers/WMwall1024x768.gif'
pixbuf = gtk.gdk.pixbuf_new_from_file(path)
widget.window.draw_pixbuf(widget.style.bg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0,0)
window = gtk.Window()
window.set_title('Drawing Test')
window.set_size_request(640,480)
window.connect('destroy',gtk.main_quit)
hbbox = gtk.HButtonBox()
window.add(hbbox)
hbbox.connect('expose-event', draw_pixbuf)
button = gtk.Button('Press Me!')
hbbox.pack_start(button, True, False, 10)
window.show_all()
gtk.main()
I also found a C example at:
http://www.gtkforums.com/viewtopic.php?t=446
Code
GtkWidget *SetupWindow(gchar *data,gboolean Transient)
{
GdkPixmap *background;
GdkPixbuf *pixbuf;
GdkScreen *ourscreen;
GdkColormap *colormap;
GtkStyle *style;
GdkColor fg;
GdkColor bg;
GError *error = NULL;
GdkRectangle *rect;
GtkWidget *window;
pixbuf = gdk_pixbuf_new_from_file ("pics/fb.png",&error);
if (error != NULL) {
if (error->domain == GDK_PIXBUF_ERROR) {
g_print ("Pixbuf Related Error:\n");
}
if (error->domain == G_FILE_ERROR) {
g_print ("File Error: Check file permissions and state:\n");
}
g_printerr ("%s\n", error[0].message);
exit(1);
}
gdk_pixbuf_render_pixmap_and_mask (pixbuf, &background, NULL, 0);
style = gtk_style_new ();
style->bg_pixmap[0] = background;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), data);
// gtk_window_maximize(GTK_WINDOW(window));
gtk_window_set_modal (GTK_WINDOW (window),TRUE);
gtk_window_set_default_size(GTK_WINDOW(window),640,480);
gtk_widget_set_style (GTK_WIDGET(window), GTK_STYLE(style));
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS);
gtk_container_set_border_width(GTK_CONTAINER(window), 14);
if(Transient==TRUE)
gtk_window_set_transient_for(GTK_WINDOW (window),GTK_WINDOW(mainwindow));
gtk_widget_show (window);
return(window);
}
But I didn't try it.
这篇关于GTK改变窗口的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!