
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to Use Images as Backgrounds in Tkinter?
If we will create an instance of Tkinter frame and display the window while keep running it, then it will show the default output canvas. However, we can add an image inside the Tkinter canvas as a background using PhotoImage methods and Canvas methods.
Since image support in Tkinter is limited to Gif, PNG and PPM, the PhotoImage(GIF, PNG, PPM) function takes the location of the image file and displays the canvas with the image as a background.
First, we will create a PhotoImage Object using the PhotoImage function.
Example
from tkinter import * from PIL import ImageTk win = Tk() win.geometry("700x300") #Define the PhotoImage Constructor by passing the image file img= PhotoImage(file='down.png', master= win) img_label= Label(win,image=img) #define the position of the image img_label.place(x=0, y=0) win.mainloop()
Output
Running the above code snippet will display a window with a background image.
- Related Articles
- How to use Bitmap images in Button in Tkinter?
- How to use images in Tkinter using photoimage objects?
- Configure tkinter/ttk widgets with transparent backgrounds
- How to draw images in the Tkinter window?
- How to use an Image as a button in Tkinter?
- How to use SVG images in HTML5?
- Convert Images to PDFs using Tkinter
- How to use images with HTML5 canvas?
- How to use Thread in Tkinter Python?
- How do I update images on a Tkinter Canvas?
- How to use Android Picasso Library to download images?
- Resizing images with ImageTk.PhotoImage with Tkinter
- How to save figures to pdf as raster images in Matplotlib?
- How to use rgb color codes in tkinter?
- How to use a custom font in Tkinter?

Advertisements