JPGE image is not displayed in Tkinter

Asked 1 years ago, Updated 1 years ago, 382 views

What's troubling you

The JPEG image is not displayed on Tkinter.
png images and ico images are recognized, but only jpeg is impossible.

I have installed the pillow before executing the code, but it doesn't work.There are no errors in the code.

Tried

Restart PC
Verify the path is correct

Actual Code

#Import
import tkinter
from PIL import ImageTk, Image

# Creating a Window
root=tkinter.Tk()
root.title('Image practice!')
root.iconbitmap('icon.ico')
root.geometry ('800x600')
root.resizable(0,0)

# image placement
image_1=tkinter.PhotoImage(file='sukahu.png')
label_1=tkinter.Label(root, image=image_1)
label_1.pack()

button_1=tkinter.Button(root, image=image_1)
button_1.pack()

image_by_pillow=ImageTk.PhotoImage(Image.open('2.jpg')
label_2=tkinter.Label(root, image=image_by_pillow)
label_2.pack()

# Window Loop Processing
root.mainloop()

python tkinter

2022-12-22 22:51

1 Answers

It is difficult to write in the comments section, so I will check in the answer section.
The images may be too big and overlapping.

If you correct it as below, you may see 2.jpg.

root.geometry('1000x1000')
label_1.pack (side=tkinter.TOP)
button_1.pack (side=tkinter.RIGHT)
label_2.pack (side=tkinter.BOTTOM)


2022-12-22 22:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.