There is no way to change the border color of a widget, the border color is tied to the background color of the widget. Instead, you can turn off the border, and then use a frame widget where you can set the background color of the frame.
We can customize the tkinter widgets using the tkinter. ttk module. Tkinter. ttk module is used for styling the tkinter widgets such as setting the background color, foreground color, activating the buttons, adding images to labels, justifying the height and width of widgets, etc.
Build A Paint Program With TKinter and Python In order to change the background color and foreground color of a tkinter frame, we can assign different values to the bg and fg parameters in the Frame function.
foreground − Foreground color for the widget. This can also be represented as fg.
Just use
widget.config(highlightbackground=COLOR)
Furthermore, if you don't want that border at all, set the highlightthickness
attribute to 0 (zero).
You have to set the two highlights (with and without focus) to have a continuous color.
from tkinter import *
root = Tk()
e = Entry(highlightthickness=2)
e.config(highlightbackground = "red", highlightcolor= "red")
e.pack()
root.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With