Uncategorized

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.
 

 

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:


 
 

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:


 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *