How to set background image on tkinter window



In this section we will be learning how to set background image to any tkinter image

steps:

  1. Image object need to be created.
  2. Create a label, and pass the image object created in step1.
  3. while packing Label, assign BOTH(X and Y) to fill and pass YES to expand, so images can expand.
  4. Step 3 is important to display background image, while placing Widgets on top of background image. 


below is the code to set background on main window, for the above screen-shot


#program

try :
from Tkinter import * # supports Python 2
except:
from tkinter import * # supports Python 3


mw = Tk()
mw.title(
"AETies : Automation Expert Technologies")
mw.geometry(
'550x150+10+50')

pic = PhotoImage(
file="./bg_2.png")
lbl = Label(mw
, image=pic)
lbl.pack(
fill=BOTH, expand=YES)

mw.mainloop()



To place widgets on top of the background image, step 3 is mandatory.

Without step 3, background image will be set and visible until any widget is paced on top of that, the moment you place any widget, image will not be visible.

click here




Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India