我正在开发一个程序,其中包含一个输入框部件。当用户点击按钮时,如果该输入框为空,则程序会将其边框颜色更改为红色。但是当我尝试时,边框仍然保持原来的颜色,即黑色。
以下是代码:
然后在检查是否为空的if语句中,有这个来将其改为红色,但似乎没有起作用:
有人能解释一下为什么这个不起作用吗?我做错了什么?还有修复的方法吗?提前谢谢。
更新: 如请求所示,以下是剩余的代码:
以下是代码:
self.timeField = Entry(self.mfr, width=40, relief=SOLID, highlightbackground="red", highlightcolor="red")
self.timeField.grid(row=0, column=1, sticky=W)
然后在检查是否为空的if语句中,有这个来将其改为红色,但似乎没有起作用:
self.timeField.config(highlightbackground="red")
self.timeField.config(highlightcolor="red")
有人能解释一下为什么这个不起作用吗?我做错了什么?还有修复的方法吗?提前谢谢。
更新: 如请求所示,以下是剩余的代码:
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")