Tkinter Button bg

Tkinter Button bg option sets the background color of button.

In this tutorial, we will learn how to use bg option of Button() class with examples.

Color Values for Button Background

The value that has to be passed for this option is a string specifying the proportion of red, green, and blue in hexadecimal digits. You can also pass a standard color like red, green, black, white, etc.

Following are the different types of color values that you can provide to bg option.

#4 bits per color
tkinter.Button(window_main, bg='#rgb') #f00, #8af
#8 bits per color
tkinter.Button(window_main, bg='#rrggbb') #ff853a
#12 bits per color
tkinter.Button(window_main, bg='#rrrgggbbb') #ff8aba53a
#standard color names
tkinter.Button(window_main, bg='red') #red, green, yellow, blue
ADVERTISEMENT

Example 1 – Tkinter Button Background Color

In the following program, we will change the background color of Tkinter Button.

example.py – Python Program

import tkinter

window_main = tkinter.Tk(className='Tkinter - TutorialKart', )
window_main.geometry("400x200")

button_submit = tkinter.Button(window_main, text ="Submit", bg='#8ed49f')
button_submit.config(width=20, height=2)

button_submit.pack()
window_main.mainloop()

Output

Tkinter Button Background Color

Conclusion

In this Python Tutorial, we learned about Tkinter Button bg option, to change background color, with the help of example Python programs.