Search code examples
pythonimagepython-3.xtkinterphotoimage

TKinter python 3.x resizing an image


I would like to resize an image using TKinter. Please note that I will not be using PIL for this.

How can I currently have this image, which works fine.

logo = PhotoImage(file="logo_dribbble-01_1x.PNG")
label = Label(f1,image=logo, borderwidth=0, highlightthickness=0)
label.pack()

logo_dribbble-01_1x.PNG

I would like to resize this image so that the logo looks smaller.

I tried doing this, which was suggested here

smallLogo = PhotoImage(file="logo_dribbble-01_1x.PNG")
smallLogo = smallLogo.subsample(2, 2)
smallLabel = Label(f1,image=smallLogo, borderwidth=0, highlightthickness=0)
smallLabel.pack()

But this creates an empty label without displaying the image.

I tried to resize the image using Photoshop and use that image and then use that .png image to display the smaller image like so:

logo = PhotoImage(file="logo_dribbble-01_1xsmall.PNG")
smallLabel = Label(f1,image=smallLogo, borderwidth=0, highlightthickness=0)
smallLabel.pack()

logo_dribbble-01_1xsmall.PNG

But, I get this error when I try to run the code _tkinter.TclError: encountered an unsupported criticial chunk type "mkBF"

How can I resolve this issue?


Solution

  • I had to keep a reference of the image that was being used by the label like so:

    logo = PhotoImage(file="image.png")
    logo = logo.subsample(2, 2)
    label = Label(root,image=logo, borderwidth=0, highlightthickness=0)
    label.image = logo
    label.pack()