0

Estoy tratando de poner una imagen en una label de una interfaz, pero cuando corro el programa me sale es siguiente error

Traceback (most recent call last): File "C:\Users\Familia\Desktop\Archivos programación\Programación\proyecto F\prueba tkinter ventana.pyw", line 18, in imagen=Tkinter.PhotoImage(file="tec.jpg") File "C:\Python27\lib\lib-tk\Tkinter.py", line 3377, in init Image.init(self, 'photo', name, cnf, master, **kw) File "C:\Python27\lib\lib-tk\Tkinter.py", line 3331, in init self.tk.call(('image', 'create', imgtype, name,) + options) TclError: couldn't recognize data in image file "tec.jpg"

Este es mi códico

import Tkinter

ventana= Tkinter.Tk()
ventana.geometry("500x500")
ventana.title("Pruebas sudoku")
ventana.resizable(0, 0)
ventana.iconbitmap("logo1.ico")

miframe=Tkinter.Frame(ventana)
miframe.pack()
dato=Tkinter.StringVar()
caja1=Tkinter.Entry(ventana, textvariable=dato)
caja1.place(x=150, y=10)

ltexto=Tkinter.Label(ventana, text="etiqueta texto", font=18)
ltexto.place(x=50, y=10)

imagen=Tkinter.PhotoImage(file="tec.jpg")
limagen=Tkinter.Label(miframe, image = imagen)
limagen.image = imagen
ventana.mainloop()

P.D: ya traté de poner la ruta de la imagen, usar otras imágenes y poner la label en la ventana y no en el frame

Estoy usando pthon 2.7

1 respuesta 1

0

La clase PhotoImage de tkinter, soporta los formatos: PGM, PPM, GIF, PNG. Si deseas trabajar con otros formatos, pudieras utilizar Python Imaging Library (PIL) , que contiene clases que te permiten utilizar alrededor de 30 formatos, convirtiéndolos en objetos compatibles con Tkinter. PIL podrías utilizarlo de la siguiente forma:

from PIL import Image, ImageTk
imagen = Image.open("tec.jpg")
foto = ImageTk.PhotoImage(imagen)
limagen=tkinter.Label(miframe, image = foto)
limagen.image = imagen
limagen.pack()

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.