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:
But after choosing the image it changes to this:
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.