我正在开发一个程序,它有一个入口小部件。当用户点击一个按钮,输入窗口小部件为空时,如果边框颜色变为红色,程序就会改变边框颜色。但当我尝试时,边界保持不变。那是黑色的。
代码如下:
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")
以高光厚度解决问题
您给出的代码应该可以工作,尽管您可能会碰到平台实现(即:windows可能不会像对待其他平台一样对待高光厚度)
这是一个应该可以工作的程序,尽管我还没有在Windows7上测试过它:
使用帧模拟边界
另一个解决方案是创建一个边框,边框比按钮稍大。这里有一个简单的例子。它并没有真正准备好生产,但它说明了一点:
相关问题 更多 >
编程相关推荐