Tkinter

How to Change Background Color of a Tkinter Button in Python

In this tutorial, we are going to see how to change the background color of a Tkinter Button in Python. You are able to change the background color of a button in Python by defining the “bg” property of the Tkinter button to a color string or HEX value.

Assign a standard color or a hexadecimal RGB value to the “bg” property as shown below.
 

 

Example 1: Change Background Color of a Tkinter Button
from tkinter import *   

gui = Tk()  
gui.geometry('200x100')  
  
btn = Button(gui, text = 'Click here!', bg='yellow')  
btn.pack()  
  
gui.mainloop()

Output:


 
 

Example 2: Change Background Color of a Tkinter button to hexadecimal color
from tkinter import *   

gui = Tk()  
gui.geometry('200x100')  
  
btn = Button(gui, text = 'Click here!', bg='#96c0eb')  
btn.pack()  
  
gui.mainloop()

Output:


 
 

Example 3: Change Background Color of a Tkinter button to black
from tkinter import *   

gui = Tk()  
gui.geometry('200x100')  
  
btn = Button(gui, text = 'Click here!', bg='black', fg='white')  
btn.pack()  
  
gui.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 *