- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to reset the background color of a Python Tkinter button?
Tkinter buttons are useful for handling events within the application. We can configure the button properties such as text style, font-family, background color, text color, and text size using predefined properties.
We can reset the background color and other properties by defining a callback function.
Example
#Import the tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win= Tk() #Define the geometry of the function win.geometry("750x250") #Define a function to change the properties of button def change_color(): btn.configure(bg="OrangeRed3", fg= "white") #Create a Label Label(win, text= "Click the Button to reset the Color of the Button", font= ('Georgia 16 italic')).pack(pady=30) #Create a button to close the window btn = Button(win, text ="RESET", command=change_color, font=('Georgia 11')) btn.pack(side=TOP, ipady=5, ipadx=20) win.mainloop()
Output
Running the above code will display a window that contains a button and a text in it.
Now, click the "RESET" button to change the background as well as the foreground color of the button.
- Related Articles
- How to make a Button Hover to change the Background Color in Tkinter?
- How to set the background color of a ttk.Combobox in tkinter?
- How to change the background color of a Treeview in Tkinter?
- How to change the background color of a tkinter Canvas dynamically?
- How to change a button background color using Swift?
- Setting Background color for Tkinter in Python
- Change the background color of a button with CSS
- How to change the color of ttk button in Tkinter?
- How do I get the background color of a Tkinter Canvas widget?
- How to change the menu background color of Tkinter's OptionMenu widget?
- Changing the background color of a tkinter window using colorchooser module
- Dynamically change the widget background color in Tkinter
- Add a blue background color to simulate a pressed button in Bootstrap
- Change the color upon hovering over Button in Tkinter
- How to exit from Python using a Tkinter Button?

Advertisements