Label Using Function in tkinter python
Label is a Tkinter Widget class, which is used to display text or an image.
Example:
from tkinter import *
my_window= Tk()
my_window.title("Change Color of Tkinter Label")
my_window.geometry("800x500+450+86")
my_window.config(bg="#B4EEB4")
def color_change():
lbl1.config(bg="red", fg="green")
lbl2.config(bg="#00FFFF", fg="#000000")
lbl3.config(bg="#9C661F", fg="#F0FFFF")
lbl4.config(bg="#76EE00", fg="#F0FFFF")
def reset_color():
lbl1.config(bg="white", fg="black")
lbl2.config(bg="white", fg="black")
lbl3.config(bg="white", fg="black")
lbl4.config(bg="white", fg="black")
lbl1 = Label(my_window, text="I am a Label 1", font=("helvetica", 30,"bold"))
lbl2 = Label(my_window, text="I am a Label 2", font=("helvetica", 30,"bold"))
lbl3= Label(my_window, text="I am a Label 3", font=("helvetica", 30,"bold"))
lbl4= Label(my_window, text="I am a Label 4", font=("helvetica",30,"bold"))
btn_change= Button(my_window, text="Change Color",bg="#EE6363",font=("times",20,"bold"),
command=color_change)
btn_reset= Button(my_window, text="Reset Color",bg="#EE6363",font=("times",20,"bold"),
command=reset_color)
lbl1.pack(padx=30, pady=10)
lbl2.pack(padx=30, pady=10)
lbl3.pack(padx=30, pady=10)
lbl4.pack(padx=30, pady=10)
btn_change.pack(padx=30, pady=10)
btn_reset.pack(padx=30, pady=10)
my_window.mainloop()
Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.
Enjoy..............
إرسال تعليق