How to Change Label Background Color in Tkinter
In this tutorial, we are going to see how to change label background color in Tkinter. The default color of a Tkinter Label is gray. You can change this to any color you want depending on your application needs.
There are two ways to change the color of a Label in Tkinter:
- By using the configure(bg = ‘ ‘) method of the tkinter.Tk class.
- Or set the bg property of tkinter.Tk directly.
In both cases, set the bg property with a valid color value. You can provide a valid color name or a 6-digit hexadecimal value with # preceding the value, as a string.
[st_adsense]
How to Change Label Background Color in Tkinter Using Configure
In the following example, we will change the color of the Tkinter Label to yellow.
import tkinter as tk root = tk.Tk() label = tk.Label(root, text="Welcome to StackHowTo!") label.config(bg="yellow") label.pack() root.mainloop()
Output:
[st_adsense]
How to Change Label Background Color in Tkinter Using bg property
In the following example, we will change the color of the Tkinter Label to yellow.
import tkinter as tk root = tk.Tk() label = tk.Label(root, bg="yellow", text="Welcome to StackHowTo!") label.pack() root.mainloop()
Output:
[st_adsense]