change color of a Tkinter label Using Function

If You Want to Change Your Lable color Using Button You can Follow Below Step.


Example:

from tkinter import *


my_window= Tk()
my_window.title("Change Color of Tkinter Label")
my_window.geometry("800x350+450+86")
my_window.config(bg="#B4EEB4")


def color_change():
lbl.config(bg="red", fg="green")


lbl = Label(my_window, text="I am a Label", font=("helvetica", 30,"bold"),
                   borderwidth=30)
lbl.pack(pady=20)
btn=Button(my_window,text="Change Color",bg="#EE6363",fonttimes",20,"bold"), 
                    command=color_change)
btn.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 Enjoy...........

Post a Comment

Previous Post Next Post