Ảnh đối tượng hữu ích mọi ứng dụng. Xử lý ảnh Tkinter dùng Pillow/PIL Python. Có hàm tích hợp: tải ảnh, trích xuất, cấu hình khung ảnh.
Ví dụ
Thêm ảnh bằng hộp thoại chọn file, hiển thị bằng Label.
#Import Tkinter library
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from PIL import Image, ImageTk
#Tạo instance Tkinter frame
win= Tk()
#Đặt geometry
win.geometry("750x350")
win.title("Image Gallery")
def select_file():
path= filedialog.askopenfilename(title="Select an Image", filetype=(('image files','*.jpg'),('all files','*.*')))
img= Image.open(path)
img=ImageTk.PhotoImage(img)
label= Label(win, image= img)
label.image= img
label.pack()
#Tạo Label và Button mở dialog
Label(win, text="Click the Button below to select an Image", font=('Caveat 15 bold')).pack(pady=20)
button= ttk.Button(win, text="Select to Open", command= select_file)
button.pack(ipadx=5, pady=15)
win.mainloop()
Kết quả
Chạy mã hiển thị cửa sổ nút chọn ảnh, hiển thị ảnh.

Chọn ảnh từ thư mục, hiển thị kết quả.
