So, I have just spent the better part of eternity trying to figure out how to remove the hover over button colour change effect that comes standard with TTKBootstrap (Python module to make nicer GUIs).
It is my sincere hope that I can save at least one person 5 hours figuring this out by themselves, here is the code that I got to FINALLY work:
# Setup of main window
root = ttk.Window()
# Configure the GUI styles
style = ttk.Style()
style.theme_use("litera")
# Configure fonts and sizes
style.configure('.', font=('Terminal', 20))
style.configure('Treeview', rowheight=50)
# This code removes the hover effect from Outline.TButton objects
style.configure('primary.Outline.TButton')
style.map('primary.Outline.TButton',
background=[("pressed", style.colors.primary),
("active", style.colors.bg)],
foreground=[("pressed", style.colors.bg),
("active", style.colors.primary)]
)
There were a couple of key issues I discovered along the way:
-
For whatever reason, you must first create the window (root = ttk.Window()) then set the style separately. I have no idea why, but if you set the style in the line where you instantiate the main window this doesnt work
-
You must set both a style.configure and a style.map, and they must be in that order for this to work
-
The syntax for calling methods and what not inside style and getting it to do things is quite finnicky and should you make a mistake, style will just keep trucking and either ignore what you asked or better it will corrupt the style and make GUI behaviour unpredictable.
-
You will need to make one of these conf/map code blocks for each of the types of buttons you want to use without hover effect (ie primary, warning etc).
Mostly covered above. Spent alot of time working through this, hopefully someone can cut and paste the above and modify to their needs without wasting time like i did.
Llama Del Rae is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.