I am trying to change the focus color of a ttk.Entry
widget in python (blue border):
I know that we can change the focus color of the notebook tabs with style.configure('Tab', focuscolor='red')
, so I wonder how to do it with an entry widget?
Here is my code:
import tkinter
from tkinter import ttk
root = tkinter.Tk()
style = ttk.Style()
style.theme_use('clam')
style.configure('TEntry', focuscolor='red') # don't work
ttk.Entry(root).grid(padx=10, pady=10)
root.mainloop()
CodePudding user response:
As suggested by @Thingamabobs and @acw1668 It's possible to change the focus color of a ttk.Entry
by mapping the focus state in its style property. Here is the working code:
import tkinter
from tkinter import ttk
root = tkinter.Tk()
style = ttk.Style()
style.theme_use('clam')
style.map('TEntry', lightcolor=[('focus', 'white')])
ttk.Entry(root).grid(padx=10, pady=10)
root.mainloop()
My final goal was to hide the focus border so I changed its color to white (the background color), and now the result looks like this: (The black border is just the original border of the entry)