The approach will be to use config()
.
You can change the color of an element using the following code:
from tkinter import *
from tkinter import colorchooser
#Creating the window and setting it's size
root = Tk()
root.geometry("500x500")
#Function to show the color chooser
def choosecol(*args):
global colorchosen
colorchosen = colorchooser.askcolor(title="Choose color")
#Function to change the background color of the label.
def changecol(*args):
lbl.config(bg=colorchosen[1])
#Creating the label which will change it's color
lbl = Label(root, text="My color will change.")
lbl.place(x=300, y=200)
#Button which will show the color chooser when clicked
btn = Button(root, text="Click me", command=choosecol)
btn.place(x=200, y=200)
#Button which will change the color to the color chosen using the previous button
changebtn = Button(root, text="Change color", command=changecol)
changebtn.place(x=200, y=250)
#Starting the window
root.mainloop()
Like this, you can set the color of any element.
You can also change the element's foreground using elementsname.config(fg=(color))
.
Here are some more links to websites which explain how to customize the Tkinter widgets: