टिंकर में छवियों के साथ काम करने के लिए, पायथन पीआईएल या पिलो टूलकिट प्रदान करता है। इसमें कई अंतर्निहित कार्य हैं जिनका उपयोग विभिन्न स्वरूपों की छवि को संचालित करने के लिए किया जा सकता है।
कैनवास विजेट में एक छवि खोलने के लिए, हमने create_image(x, y, image, **options) का उपयोग किया है निर्माता। जब हम इमेज वैल्यू को कंस्ट्रक्टर को पास करते हैं, तो यह इमेज को कैनवास में प्रदर्शित करेगा।
उदाहरण
# Import the required libraries
from tkinter import *
from PIL import Image, ImageTk
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x600")
# Create a canvas widget
canvas=Canvas(win, width=700, height=600)
canvas.pack()
# Load the image
img=ImageTk.PhotoImage(file="Monalisa.png")
# Add the image in the canvas
canvas.create_image(350, 400, image=img, anchor="center")
win.mainloop() आउटपुट
उपरोक्त कोड को चलाने से एक विंडो प्रदर्शित होगी जिसमें कैनवास में छवि होगी।
