How to Set Background Color in Label 


Set the Background Color Behind The Label.


Syntax: bg="Color_Name Or Color_Code"


Example :

from tkinter import *
my_window = Tk()
my_window.title("Label Background Color")
my_window.config(bg="#B4EEB4")                          #root Window background color
my_window.geometry("800x350+450+86")

lbl1 = Label(my_window, text="I AM Label 1", font=("Helvetica", 25, "bold")) 
                            #does not set Background Color.(Show Default)
lbl2= Label(my_window, text="I Am Label 2", font=("Vrinda", 30, "bold"), bg="red"
#set background Color.
lbl3= Label(my_window, text="I Am Label 3", font=("Vrinda", 35, "bold"),         
                    bg="#B4EEB4")  #background Color same as Root window.

lbl1.pack(pady=20)
lbl2.pack(pady=10)
lbl3.pack(pady=20)

my_window.mainloop() 

Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.


Lets Start Python Tkinter and Enjoy.................. 

Post a Comment

Previous Post Next Post