Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to insert an image inside tha frame using tkinter library

What I have tried:

Python
from tkinter import *
from PIL import  ImageTk, Image
root =Tk()
root.geometry("1366x768")

frame_image = Frame(root, borderwidth=2, bg="white", relief=SUNKEN)
frame_image.pack(side=TOP, fill="x")


my_image = ImageTk.PhotoImage(Image.open("C:/Users/ABC/PycharmProjects/pythonProject/colleage.jpg"))
my_image = PhotoImage(frame_image, image=my_image)
my_image.pack()

mainloop()
Posted
Updated 24-Nov-21 2:00am
v2

1 solution

You do not need to use the PIL image processing library, as tkinter handles image display.
Python
from tkinter import *
root =Tk()
root.geometry("800x400")

frame_image = Frame(root, borderwidth=2, bg="white", relief=SUNKEN)
frame_image.pack(side=TOP, fill="x")

frame_image.picture = PhotoImage(file="C:/Users/ABC/PycharmProjects/pythonProject/colleage.jpg")
frame_image.label = Label(frame_image, image=frame_image.picture)
frame_image.label.pack()

mainloop()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900