 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
How to 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
 