gpt4 book ai didi

python - PyGTK 设置窗口图标与库存图片

转载 作者:太空狗 更新时间:2023-10-30 00:00:29 26 4
gpt4 key购买 nike

我觉得这应该很简单,但我想我遗漏了一些东西。

所以我想用一张图片设置一个窗口的图标。我试过:

windowIcon = gtk.image_new_form_stock(gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_MENU)
window.set_icon(windowIcon.get_pixbuf())

然后 Python 提示说:

File "./sample.py", line 44, in init
window.set_icon(windowIcon.get_pixbuf())
ValueError: image should be a GdkPixbuf or empty

我尝试将 gtkImage 转换为 GdkPixbuf,因为当我不这样做时 python 会提示

TypeError: icon should be a GdkPixbuf or None

在 pygtk 文档中它说:

If the storage type of the image is not either gtk.IMAGE_EMPTY or gtk.IMAGE_PIXBUF the ValueError exception will be raised.

所以我猜测库存图像的存储类型是错误的。问题是我该如何解决这个问题?

最佳答案

您可以在任何 GtkWidget 上使用 .render_icon() 方法来提供库存项目作为图标。

windowicon = window.render_icon(gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_MENU)
window.set_icon(windowicon)

关于python - PyGTK 设置窗口图标与库存图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5746620/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com