Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 Tkinter Pillow Library Tutorial to Set Background Image of Label Widget GUI Desktop App

Posted on November 16, 2022

Welcome folks today in this blog post we will be setting the background image of label widget using the pillow library in python. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

Python
1
2
3
4
5
6
7
8
9
# importing required packages
import tkinter
from PIL import ImageTk, Image
 
# creating main window
root = tkinter.Tk()
 
# running the application
root.mainloop()

 

 

As you can see in the above code we are importing the pillow library and then we are also importing the tkinter library. And then we are initializing the tkinter window and then we will be running the app using the mainloop() method.

 

 

Python
1
2
# loading the image
img = ImageTk.PhotoImage(Image.open("profile.jpg"))

 

 

As you can see we are using the photoImage() method and inside it we are setting the path of the image. This image can be PNG or JPEG.

 

 

Now we will be adding the image as the background of the label widget using the label method and then we are also adding it to the window using the pack() method.

 

 

Python
1
2
3
4
5
6
# reading the image
panel = tkinter.Label(root, image = img)
 
# setting the application
panel.pack(side = "bottom", fill = "both",
expand = "yes")

 

Recent Posts

  • React.js Twitter API Tutorial to Embed Profile & Timeline, Hashtags of User in Browser Using Javascript
  • Android Java Tutorial to Change Styles & Visibility of System Bars (Top, Action & Status) Full Example
  • Android Java Project to Display & Play Audio Files From Storage inside ListView Using MediaPlayer Class
  • Android Java Project to Build MP4 Video to MP3 Audio Converter Using MediaMuxer Class
  • Android Java Project to Merge Multiple PDF Documents From Gallery Using iTextPDF Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme