English 中文(简体)
How to set bg image of a window in a GTK3 application
原标题:
  • 时间:2011-05-27 22:08:59
  •  标签:
  • gtk
  • gdk
  • gtk3

I found this way:

GdkPixmap *backPixMap = gdk_pixmap_create_from_xpm ( window , NULL , NULL , fileName );
gdk_window_set_back_pixmap( GTK_WIDGET( window )->window , backPixMap , FALSE );

but it seems that GdkPixmap is obsolete now...

So, with GTK3, how can I set the background image of a GtkWindow?

问题回答

You just need to use an Overlay. Following is an example.

class Window(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)

        self.overlay = Gtk.Overlay()
        self.add(self.overlay)

        self.bg = Gtk.Image()
        # Load file. Optionally scale it for window
        self.bg.set_from_file(BACKGROUND_IMAGE)
        # Wrapping in the Scrollable make it resizable.
        scrollable_wrapper = Gtk.ScrolledWindow()
        scrollable_wrapper.add(self.bg)
        scrollable_wrapper.set_size_request(700, 500)

        self.overlay.add(scrollable_wrapper)
        text = Gtk.Label("Test")
        self.overlay.add_overlay(text)

        self.connect( destroy , lambda w: Gtk.main_quit())
        self.show_all()


Window()
Gtk.main()




相关问题
Pointers in Lisp?

I ve started learning Lisp recently and wanted to write a program which uses gtk interface. I ve installed lambda-gtk bindings (on CMUCL). I want to have putpixel/getpixel ability on a pixbuf. But I ...

In Gtk, how do I make a Button with just a stock icon?

I want to create a button with the stock "Remove" icon on it, but without the text "Remove". If I use Button button = new Button(Stock.Remove);, I get the opposite: just the text, and no icon. I will ...

Using GtkMenu in Gtk+-2.14.0

I am building an application which has GtkMenu widget. I am using Glade RAD tool to develop UI and while creating project in Glade I have specified version of GTK as 2.16 which supports GtkMenu and ...

Can you set the FileFilters for a Gtk Dialog in Glade?

In my code, I have lines like this: Builder builder = new Builder(); builder.AddFromFile(gladefile); FileChooserDialog dialog = (FileChooserDialog) builder.GetObject("dialog"); FileFilter[] ...

热门标签