- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 draw images in the Tkinter window?
To process images with Tkinter and other Python packages, we generally refer to use Pillow Package or PIL in Python. It provides a way to load and process the images in the program wherever we need. Initially, we convert the image to an instance of PhotoImage object that allows images to be further used in many use cases. Further, the Canvas widget in Tkinter helps to draw the images in a Tkinter application, we can use the create_image(x,y, image_file) method to display the image in a particular application.
#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()
Running the above code will display a window that will display an image in the Canvas Widget.
In order to replace or change the Image file in the given output just import the image in Image.Open(file name) method.
- How to keep the window focus on the new Toplevel() window in Tkinter?
- How to show webcam in TkInter Window?
- Tkinter-How to get the current date to display in a tkinter window?
- How to make Tkinter Window appear in the taskbar?
- How to Use Images as Backgrounds in Tkinter?
- How to put a Toplevel window in front of the main window in Tkinter?
- Function to close the window in Tkinter
- How to control automated window resizing in Tkinter?
- How to use Bitmap images in Button in Tkinter?
- How to center a window on the screen in Tkinter?
- How to close only the TopLevel window in Python Tkinter?
- How to use images in Tkinter using photoimage objects?
- How to resize the background image to window size in Tkinter?
- How to make a Tkinter window jump to the front?
- How to bind the Enter key to a tkinter window?