python - 如何使用 pygtk 在窗口中包含图像?

标签 python image gtk pygtk

我正在尝试用 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/

相关文章:

python - 使用坐标点生成热图

python - 从推文中过滤图像

html - CSS 中的图像映射?

javascript - 使用Canvas将不透明像素变成白色

c# - 在 Gtk 中,如何动态设置窗口的高度和宽度?

python - 给定 4 个点,如何在 Python 中定义超平面?那么我如何定义 4 个超平面的交点(这应该是一个点)?

python - boolean 掩码每行中不同长度的列表

python - 将遵循一个方向的一组点组合在一起的算法

Python GTK (Glade) 笔记本

python - 如何向 GTK 小部件添加额外数据?