[pygtk] image on a Button
Gorse Emmanuel
e.gorse at gmail.com
Wed Sep 30 14:56:59 WST 2009
Thanks for the answer.
I'm checking the imgFullFile with os.path.exists() before loading it,
so the absolute path of the image is correct.
As img.set_from_file() doesn't raise an exception when it can't load
the file, i've tried with this:
img = gtk.Image()
pixBuf = gtk.gdk.pixbuf_new_from_file(imgFullFile)
img.set_from_pixbuf(pixBuf)
button.set_image(img)
and gtk.gdk.pixbuf_new_from_file() didn't raise an exception, but the
image is still not displayed.
Furthermore, i'm also using an IconView to display the images, and
they are displayed just fine. The code is:
store = gtk.ListStore(str, gtk.gdk.Pixbuf)
for name in xxx:
pixbuf = gtk.gdk.pixbuf_new_from_file(imgFullFile)
store.append([name, pixbuf])
So the image loading seems fine but images don't get displayed on the buttons...
2009/9/30, sandbox_mail <sandbox_mail at yahoo.de>:
> I did not try it out but my first guess is: the image is not found in
> Windows due to the different path syntax.
>
> In linux you will have a path like /home/user/picture.jpg but in windows
> 1.) there is no /, instead \ is used
> 2.) absolute paths start at the drive letter like C:\Users\picure.jpg
>
> I believe python's "os" module will help you build the correct paths
> depending on which system the code is running.
>
> Gorse Emmanuel wrote:
>> Hye,
>>
>> I'm using this code to display an image on a button:
>>
>> img = gtk.Image()
>> img.set_from_file(imgFullFile)
>> button.set_image(img)
>>
>> with imgFullFile beeing the absolute path of the image.
>>
>> The code works fine under Linux, but the image is not displayed under
>> Windows.
>> Do you have any idea why ?
>>
>> Regards,
>> _______________________________________________
>> pygtk mailing list pygtk at daa.com.au
>> http://www.daa.com.au/mailman/listinfo/pygtk
>> Read the PyGTK FAQ: http://faq.pygtk.org/
>>
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
More information about the pygtk
mailing list