1

Estoy tratando de reducir una imagen cargada desde tkinter pero no me esta resultando, algún héroe que pueda ayudarme a resolver este problema?

def load(self):
        global imagen
        file_name=filedialog.askopenfilename(title='Subir',filetypes=[('GIF FILES', '*.png')])  
        image= Image.open(file_name)
        image= image.resize((50, 50), Image.ANTIALIAS)
        photo = PhotoImage(image) 
        self.LabelImagen.config(image=photo)
2
  • Freddy, estás recibiendo algún error? Podrías dar más detalles? Un código de ejemplo mínimo y funcional, también ayudaría.
    – RodrigoN
    el 19 mar. 2019 a las 1:03
  • Ni un error, solo no aparece la imagen, por favor podrías remodelar mi código e intentarlo hacer a tu manera? el 20 mar. 2019 a las 18:43

1 respuesta 1

0

Freddy, como no publicaste un trozo de código completo y verificable, tuve que asumir algunas cosas, espero haber acertado.

from tkinter import Tk, Button, Label, filedialog
from PIL import Image, ImageTk as itk

class Ventana():
    def __init__(self):
        self.v = Tk()
        self.v.geometry("300x300+500+300")
        boton = Button(self.v, text="Clic", command=self.load)
        img = itk.PhotoImage(file="uno.png")
        self.lbl_imagen = Label(self.v, image=img)
        boton.place(x=10, y=10)
        self.lbl_imagen.place(x=10, y=40)

        self.v.mainloop()

    def load(self):
        file_name=filedialog.askopenfilename(title='Subir', filetypes=[('PNG FILES', '*.png')])

        pil_img = Image.open(file_name)
        wh = int(pil_img.width/2)
        pil_img = pil_img.resize((wh, wh), Image.ANTIALIAS)
        pil_img = itk.PhotoImage(pil_img)

        self.lbl_imagen.config(image=pil_img)
        self.lbl_imagen.image=pil_img  # Recomendación de la documentación de PhotoImage

ven = Ventana()

La clave de todo está en el método PhotoImage, ya que existen al menos dos de ellos, uno directamente en tkinter, y otro dentro de Pillow (PIL), es por ello que se realiza el siguiente import:

from PIL import Image, ImageTk as itk

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.