Dùng Pillow (PIL) để mở ảnh, chuyển thành ImageTk.PhotoImage, đặt vào Label bên trong Frame.
Các bước
Nhập tkinter, PIL (Image, ImageTk).
Tạo cửa sổ, Frame với width, height, đặt giữa bằng place(anchor='center', relx=0.5, rely=0.5).
Mở ảnh: ImageTk.PhotoImage(Image.open("forest.jpg")).
Tạo Label trong Frame với image=img.
Chạy mainloop.
Ví dụ
from tkinter import *
from PIL import ImageTk, Image
win = Tk()
win.geometry("700x500")
frame = Frame(win, width=600, height=400)
frame.pack()
frame.place(anchor='center', relx=0.5, rely=0.5)
img = ImageTk.PhotoImage(Image.open("forest.jpg"))
Label(frame, image=img).pack()
win.mainloop()
Kết quả
Ảnh hiển thị giữa cửa sổ trong Frame.
