skip to Main Content

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?

3

Answers


  1. Chosen as BEST ANSWER

    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()
    

  2. The following code worked for me:

    from tkinter import *
    
    f1 = Tk()
    smallLogo = PhotoImage(file="image.PNG")
    smallLogo = smallLogo.subsample(2, 2)
    smallLabel = Label(f1,image=smallLogo, borderwidth=0, highlightthickness=0)
    smallLabel.pack()
    f1.mainloop()
    

    Note I’m on tk-8.6

    Login or Signup to reply.
  3. smallLogo = PhotoImage(file="logo_dribbble-01_1x.PNG")
    smallLogo_one = smallLogo.subsample(2, 2)
    smallLabel = Label(f1,image=smallLogo_one, borderwidth=0, highlightthickness=0)
    smallLabel.pack()
    

    I think this will solve the problem for you.Your variable for PhotoImage is the same as variable for the Subsample to trim the image for you.
    I change the variable for subsample to smallLogo_one the parsed it to the image attribute in the Lable.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search