python - How to create a PixBuf from file with Gdk3? -


environment: python3

libraries:

from gi.repository import gtk, gdk import cairo 

i want create 'pixbuf file' method not longer exist in gdk3.

pb = gdk.pixbuf_new_from_file('sunshine.png') gdk.cairo_set_source_pixbuf(cr, pb, 0, 0) 

result in: attributeerror: 'gi.repository.gdk' object has no attribute 'pixbuf_new_from_file'

does know how gdk3? seems gdk3 support these methods:

gdk_pixbuf_get_from_window gdk_pixbuf_get_from_surface 

update

found out myself:

image = gtk.image() image.set_from_file('sunshine.png') pixbuf = image.get_pixbuf() gdk.cairo_set_source_pixbuf(cr, pixbuf, 10, 10) 

the question old, maybe helps someone:

from gi.repository import gdkpixbuf pixbuf = gdkpixbuf.pixbuf.new_from_file('sunshine.png') 

tested on gdkpixbuf._version == '2.0'


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -