开发者

How do I include an image in a window with pygtk?

开发者 https://www.devze.com 2023-01-15 15:48 出处:网络
I\'m trying to make a program in python which creates a fullscreen window and includes an image, but I don\'t really know how to do that. I\'ve tried to read documentations on pygtk and I\'ve searched

I'm trying to make a program in python which creates a fullscreen window and includes an image, but I don't really know how to do that. I've tried to read documentations on pygtk and I've searched in both goodle and stackoverflow, without any success. Here's 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 do开发者_开发技巧 I include an image in a window?


Please provide a little more context (e.g. class definition, imports).

Do not forget to add the image object to your window (before showing image and window):

self.window.add(image)

The tutorial example adds the image to a button, but you can try adding it directly to the main window:

# 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)
0

精彩评论

暂无评论...
验证码 换一张
取 消