- 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
Change the color upon hovering over Button in Tkinter
Let us suppose that we are creating an application in which we want to change the color of the Button widget while we hover upon it. We can have the hovering property by defining the Event Callbacks.
To change the color of the Button while hovering on it, we have to bind the <Enter> and <Leave> events. For each event, we will configure the button property such as background color, foreground color, etc.
Example
#Import required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("750x250") #Define functions def on_enter(e): button.config(background='OrangeRed3', foreground= "white") def on_leave(e): button.config(background= 'SystemButtonFace', foreground= 'black') #Create a Button button= Button(win, text= "Click Me", font= ('Helvetica 13 bold')) button.pack(pady= 20) #Bind the Enter and Leave Events to the Button button.bind('<Enter>', on_enter) button.bind('<Leave>', on_leave) win.mainloop()
Output
Running the above code will display a window that contains a button.
Now, hover over the button in the displayed window. It will change its basic color such as background color and foreground color.
- Related Articles
- How to change the color of ttk button in Tkinter?
- How to make a Button Hover to change the Background Color in Tkinter?
- Display message when hovering over something with mouse cursor in Tkinter Python
- Dynamically change the widget background color in Tkinter
- Change Color of Button in iOS when Clicked
- Change command Method for Tkinter Button in Python
- Change the color of "tab header" in ttk.Notebook (tkinter)
- How to change the mouse pointer color in Tkinter?
- Change the background color of a button with CSS
- How to change text cursor color in Tkinter?
- How do I change button size in Python Tkinter?
- How to reset the background color of a Python Tkinter button?
- How to change color of Button in Android when Clicked?
- How to change the background color of a Treeview in Tkinter?
- How to change a button background color using Swift?

Advertisements