
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use an Image for the Background in Tkinter
Background images in tkinter are versatile as the functionality can be used in making 3D, 2D games, screensaver, desktop visualizations software, etc. Tkinter canvas is used to work with all these functionalities in an application.
Example
In this example, we will add a background image using the create_image() method in the canvas widget.
#Import the required library from tkinter import * from PIL import Image, ImageTk from tkinter import ttk #Create an instance of tkinter window win= Tk() #Define the geometry of the window win.geometry("750x650") #Load the image bg= ImageTk.PhotoImage(file="./tutorialspoint.png") #Create a canvas canvas= Canvas(win,width= 400, height= 200) canvas.pack(expand=True, fill= BOTH) #Add the image in the canvas canvas.create_image(0,0,image=bg, anchor="nw") #Add a text in canvas canvas.create_text(310,550,text="</Hello,Devs!_", font= ('Courier 45 bold')) win.mainloop()
Output
Now, execute the above code to display a window that contains a background image with some text.
Advertisements