How to Use Backgroud and Foreground Color in Tkinter Label

background − Background color for the widget. This can also be represented as bg
Syntax: bg="Color/ Color_Code"

foreground − Foreground color for the widget. This can also be represented    as fg.
Syntax: fg="Color/ Color_Code"

Example:

from tkinter import *
mywindow = Tk()
mywindow.title("Background And Foreground COlor")
mywindow.geometry("800x320+500+86")
mywindow.config(bg="#F8F8FF")


label1 = Label(mywindow, text="Hello World" , bg="#FF6EB4", fg="white",
                         font=("verdana", 40, "bold"), width=15)
label2 = Label(mywindow, text="Hello World", bg="#ADFF2F", fg="red",
                        font=("helvetica", 40, "italic"), width=17)
label3 = Label(mywindow, text="Hello World", bg="#EEB422", fg="#9400D3",
                        font=("serif", 40, "bold italic"), width=18)


label1.pack(pady=10)
label2.pack(pady=20)
label3.pack(pady=20)
mywindow.mainloop()


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




Post a Comment

أحدث أقدم