0

I have declared a LabelFrame as:

img_frame = LabelFrame(root, text="Image", height=250, width=250)

Then I call a function that places img_frame, asks for an image and then updates the widget to show said image:

def open_file():
    # Place other widgets
    img_frame.place(relx=.5, rely=.3, anchor="c")
    # Place more widgets

    root.filename = # Use filedialog to choose image
    my_img = Image.open(root.filename)
    my_img.thumbnail(MAX_SIZE)  # MAX_SIZE = (220, 220)
    new_img = ImageTk.PhotoImage(my_img)
    frame_lbl = Label(image=new_img)
    img_frame.configure(labelwidget=frame_lbl)

But the image is never shown.
While I'm asked to choose the image, the LabelFrame is shown like this:
Original widget appearance.

But after choosing the image it changes to this:
Widget updated appearance.
Were the highlight of the borders appears to be cropped at the top, lowered down and the text disappears.

What am I doing wrong and what should I do to make the image to be shown?

I already tried to do it outside of the function

my_img = Label(image=ImageTk.PhotoImage(Image.open("sample.jpg")))
img_frame = LabelFrame(root, text, height, width, labelwidget=my_img)
img_frame.place(relx=.5, rely=.3, anchor="c")

and also did it using thumbnail() to change resolution but the results are the same.

jotaro-gogogo
  • 59
  • 1
  • 8
  • 1
    Does this answer your question? https://stackoverflow.com/questions/16424091 – Bryan Oakley May 27 '22 at 23:14
  • @BryanOakley it does, partly, had to make `new_img` global and now it shows, I still have to figure out how to make the highlight to remain stale and `text` not to disappear. Thanks. – jotaro-gogogo May 28 '22 at 01:23

0 Answers0