Explosive_Orange
Explosive_Orange

Reputation: 3

How to change the border color of a disabled entry widget

I'm building a calculator program and want to change the border color of my entry widget when it's in a disabled state. I tried doing the highlightcolor function but it just added a new border to the one I already had (the borderwidth). Here's what I have so far:

e = Entry(root, width=30, borderwidth=5, font=calFont) 
e.grid(row=0, column=0, columnspan=3, padx=5, pady=5, ipady=3)

e.config(state='disabled', disabledforeground='white')

Upvotes: 0

Views: 421

Answers (1)

bangKok
bangKok

Reputation: 332

I think that you are looking for this solution. highlightthickness specifies the borderwidth in combination with highlightbackground and highlightcolor you can define a specific color.

This is not a guide on how to design your app, just what it might look like:

from tkinter import *

root = Tk()

def showSmth():
    global state
    if state is True:
        btn.configure(text="Disabled")
        ent.config(state=DISABLED, highlightcolor="green", highlightbackground="green")
        state = False
    else:
        btn.configure(text="Enabled")
        ent.config(state=NORMAL, highlightcolor="blue", highlightbackground="blue")
        state = True


state = True

ent = Entry(root, bg="yellow", highlightthickness=5, highlightcolor="blue", highlightbackground="blue")
ent.pack()

btn = Button(root, text="Enabled", command=showSmth)
btn.pack()

root.mainloop()

Upvotes: 1

Related Questions