Uncategorized

How to Change Background Color of a Tkinter Button When Clicked in Python

In this tutorial, we are going to see how to change the background color of a Tkinter Button when clicked in Python. You are able to change the background color of a button, when the button was clicked, by using the activebackground property of the button.
 

Example: Change Background Color of a Tkinter Button When Clicked

In the following example, we will change the background color of the button to yellow when it is pressed.

from tkinter import *   

gui = Tk()  
gui.geometry('200x100')  
  
btn = Button(gui, text = 'Click here!', activebackground='yellow')  
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 *