How to set bg image of a window in a GTK3 application

女生的网名这么多〃 提交于 2019-12-13 07:29:50

问题


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?


回答1:


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()


来源:https://stackoverflow.com/questions/6158171/how-to-set-bg-image-of-a-window-in-a-gtk3-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!