How to include image in window with pygtk?

I am trying to create a python program that creates a full screen window and includes an image, but I really don't know how to do this. I tried to read the pygtk documentation and I searched for both goodle and stackoverflow, without any success. Here is my current code.

def __init__(self):
    pixbuf = gtk.gdk.pixbuf_new_from_file("test.png")
    image = gtk.Image()
    self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.fullscreen()
    self.window.show()
    image.set_from_pixbuf(pixbuf)
    image.show()

Question: how to include the image in a window?

+3
source share
1 answer

Indicate a little more context (e.g. class definition, import).

Remember to add an object imageto your window (before displaying the image and window):

self.window.add(image)

button, :

# an image widget to contain the pixmap
image = gtk.Image()
image.set_from_pixmap(pixmap, mask)
image.show()

# a button to contain the image widget
button = gtk.Button()
button.add(image)
window.add(button)
button.show()

button.connect("clicked", self.button_clicked)
+4

Source: https://habr.com/ru/post/1764378/


All Articles