PyGTK sets a stack icon

I feel that it should be pretty simple, but I think I'm missing something.

So, I want to set a window icon with one of the images. I tried:

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

Python then complains that:

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

I am trying to convert gtkImage to GdkPixbuf because when I did not write python,

Icon TypeError: Must be GdkPixbuf or None

The pygtk documentation says:

If the image store type is not gtk.IMAGE_EMPTY or gtk.IMAGE_PIXBUF, a ValueError exception is thrown.

So, I assume that the storage type of the source image is wrong. The question is, how do I get around this?

+6
source share
2 answers

You can use the .render_icon () method for any GtkWidget to provide a stock item as an icon.

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

The render_icon() method works as described above. Your code is having problems since the get_pixbuf() method returned None . This is because the image was not created from pixbuf , and for some reason it will not convert it. Another way to get pixbuf from an image is to use the gtk.gdk.pixbuf_new_from_image() function.

+2
source

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


All Articles