I am working on a program that has a entry widget. And when the user clicks a button and that entry widget is empty then the program will change the border color of it to red. But when I try the border just stays the same color, which is black.
Here is the code:
self.timeField = Entry(self.mfr, width=40, relief=SOLID, highlightbackground="red", highlightcolor="red")
self.timeField.grid(row=0, column=1, sticky=W)
Then in the if statement that checks if it is empty has this to change it to red but it does not seem to work:
self.timeField.config(highlightbackground="red")
self.timeField.config(highlightcolor="red")
Can someone explain to me why this is not working, what I am doing wrong, and a way to fix it? Thanks in advance.
Update: Here is the rest of the code as requested:
def start(self):
waitTime = self.timeField.get()
password = self.passField.get()
cTime = str(self.tVers.get())
self.cTime = cTime
if waitTime.strip() != "":
if password.strip() != "":
if waitTime.isdigit():
if self.cTime == "Secs":
waitTime = int(waitTime)
elif self.timeVer == "Mins":
waitTime = int(waitTime) * 60
else:
waitTime = int(waitTime) * 3600
self.password = password
root.withdraw()
time.sleep(float(waitTime))
root.deiconify()
root.overrideredirect(True)
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
self.tfr.destroy()
self.mfr.destroy()
self.bfr.destroy()
self.create_lockScreen()
else:
self.timeField.configure(highlightcolor="red")
else:
self.passFields.configure(highlightcolor="red")
else:
self.timeField.config(highlightbackground="red", highlightcolor="red")
Altough it is an old question i stumbled upon the same problem on windows 10 and there is meanwhile a fairly simple solution.
In addition to setting the highlightbackground and color you have to change the highlightthickness to something greater zero. Bryan Oekley mentioned it in the heading of his answer but i couldnt find it in his code so here is a little code snippet.
self.entry = tk.Entry(self, highlightthickness=2)
self.entry.configure(highlightbackground="red", highlightcolor="red")
(this should maybe be a comment on Bryans Answer)
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