Set Tkinter Background Color

  1. Method configure(background= )
  2. Attribute bg or background
  3. Tkinter Color Code

Tkinter widget class method configure and attribute bg or background could be used to set the Tkinter widget/window background color.

Method configure(background= )

try:
    import Tkinter as tk
except:
    import tkinter as tk
    

    
app = tk.Tk()
app.title("configure method")
app.geometry('300x200')

app.configure(bg='red')
app.mainloop()

Here,

app.configure(bg='red') configures the background color of app to be red. You could also use background instead of bg.

app.configure(background='red')

How to set Tkinter Background Color - configure method

Attribute bg or background

background or bg is one attribute in most of Tkinter widgets, and could be used to set the background color directly.

try:
    import Tkinter as tk
except:
    import tkinter as tk
    

    
app = tk.Tk()
app.title("bg attribute")
app.geometry('300x200')

app['bg'] = 'blue'
app.mainloop()

How to set Tkinter Background Color - bg attribute

Tkinter Color Code

You could specify the color with the known names like red, blue or green as shown above, and you could also specify it via RGB like hex color codes in HTML, e.g, #49A or #0059b3.

try:
    import Tkinter as tk
except:
    import tkinter as tk
    

    
app = tk.Tk()
app.title("bg attribute")
app.geometry('300x200')

app['bg'] = '#0059b3'
app.mainloop()

How to set Tkinter Background Color - HTML hex code

try:
    import Tkinter as tk
except:
    import tkinter as tk
    

    
app = tk.Tk()
app.title("bg attribute")
app.geometry('300x200')

app['bg'] = '#49A'
app.mainloop()

How to set Tkinter Background Color - HTML hex code

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.