[pyar] Cargar diferentes formatos de imagen en tkinter.ttk

Juan Carlos Ojeda juancarlospaco en gmail.com
Jue Nov 25 22:56:56 ART 2010


2010/11/25 Ernesto Savoretti <esavoretti en gmail.com>

> El día 25 de noviembre de 2010 20:50, craf <prog en vtr.net> escribió:
> > Hola.
> >
> > Estoy trabajando con tkinter.ttk y probando los estilos y temas que
> > vienen con la versión 8.5
> >
> > Con este pequeño código....
> >
> > ------------------------------------------------------------
> > from tkinter import *
> > from tkinter import ttk
> > import image
> >
> > master = Tk()
> > s = ttk.Style()
> > s.theme_use('clam')
> >
> > foto = PhotoImage(file='mi_imagen.gif')
> > b = ttk.Button(master,compound='left',image=foto,text="Hola
> > Mundo").pack()
> >
> > master.mainloop()
> > -----------------------------------------------------------
> >
> > ....estoy probando que imágenes se pueden cargar.
> > Según el manual de tkinter.ttk, solo se pueden cargar imágenes "gif",
> > pero leí que también se pueden trabajar otro tipo de formato de imágenes
> > con la librería PIL. El problema es que esta librería parece que trabaja
> > solo hasta python 2.6 y en windows (Utilizo Ubuntu).
> >
>
> No, no parece ser así. Mirá (errores incluídos)
>
> Python 2.7 (r27:82500, Oct  6 2010, 12:29:13)
> [GCC 4.5.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import PIL
> >>> img = Image.open("2.jpg")
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> NameError: name 'Image' is not defined
> >>> img = PIL.Image.open("2.jpg")
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> AttributeError: 'module' object has no attribute 'Image'
> >>> dir(PIL)
> ['__builtins__', '__doc__', '__file__', '__name__', '__package__',
> '__path__']
> >>> from PIL import Image
> >>> img = PIL.Image.open("2.jpg")
> >>> img.show()
> >>>
>
> y la mostró (creeme)
>
> 1) Estamos en ArchLinux
> 2) Python 2.7
> 3) Imagen jpg
>
> Obviamente, hay alternativas superadoras a PIL, como el port Python de
> ImageMagick, pero PIL anda.
>
> Saludos.
> --
>
>                                     Ernesto Savoretti
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>

A mi en Ubuntu me anda ese ejemplo,
pero a juzgar por como importo TK, el esta usando Python 3.1

Hacele un file archivo.jpg para ver si realmente es un JPG,
en linux la extension poco interesa...

-- 
.
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20101125/b66819b2/attachment.html>


More information about the pyar mailing list