- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to open PIL Image in Tkinter on Canvas?
Pillow package (or PIL) helps a lot to process and load images in Python projects. It is a free open-source library available in Python that adds support to load, process, and manipulate the images of different formats.
In order to open the Image in Tkinter canvas, we have to first import the library using from PIL import Image, ImageTk command. To display the image in our Tkinter application, we can use the Canvas widget by specifying the image file in the create_image(x,y,image) method.
Example
#Import the required Libraries from tkinter import * from PIL import Image,ImageTk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x270") #Create a canvas canvas= Canvas(win, width= 600, height= 400) canvas.pack() #Load an image in the script img= ImageTk.PhotoImage(Image.open("download.png")) #Add image to the Canvas Items canvas.create_image(10,10,anchor=NW,image=img) win.mainloop()
Output
Running the above code will display a window with an image inside the canvas widget.
- Related Articles
- Embedding an Image in a Tkinter Canvas widget using PIL
- How to draw a png image on a Python tkinter canvas?
- How to center an image in canvas Python Tkinter
- How to update an image in a Tkinter Canvas?
- How to insert an image in a Tkinter canvas item?
- How to Move an Image in Tkinter canvas with Arrow Keys?
- Resizing pictures in PIL in Tkinter
- How to get coordinates on scrollable canvas in Tkinter?
- How do I use PIL with Tkinter?
- How to convert Matplotlib figure to PIL Image object?
- How to convert a Torch Tensor to PIL image?
- How to create a Button on a Tkinter Canvas?
- How to draw a line on a Tkinter canvas?
- How to hide and show canvas items on Tkinter?
- How to draw an arc on a tkinter canvas?

Advertisements