我正在尝试用 python 编写一个程序,它创建一个全屏窗口并包含一个图像,但我真的不知道该怎么做。我试图阅读有关 pygtk 的文档,并且在 goodle 和 stackoverflow 中都进行了搜索,但没有成功。 这是我当前的代码。
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()
问题:如何在窗口中包含图像?
最佳答案
请提供更多上下文(例如类定义、导入)。
不要忘记将 image
对象添加到您的窗口(在显示图像和窗口之前):
self.window.add(image)
tutorial example将图像添加到 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)
关于python - 如何使用 pygtk 在窗口中包含图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3695371/