我正在开发一个具有条目小部件的程序。当用户单击按钮并且该条目小部件为空时,程序会将其边框颜色更改为红色。但是当我尝试时,边框保持相同的颜色,即黑色。
这是代码:
self.timeField = Entry(self.mfr, width=40, relief=SOLID, highlightbackground="red", highlightcolor="red")
self.timeField.grid(row=0, column=1, sticky=W)
Run Code Online (Sandbox Code Playgroud)
然后在检查它是否为空的 if 语句中将其更改为红色,但它似乎不起作用:
self.timeField.config(highlightbackground="red")
self.timeField.config(highlightcolor="red")
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释为什么这不起作用、我做错了什么以及解决它的方法吗?提前致谢。
更新:这是按照要求的其余代码:
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") …Run Code Online (Sandbox Code Playgroud) 所以我的代码有点像这样
class foo1
{
public:
foo1()
{
a = "text";
}
void getString()
{
return a;
}
private:
string a;
};
class foo2
{
public:
foo2()
{
foo3 boo3;
}
class foo3
{
public:
foo3()
{
foo1 boo1;
}
private:
foo1 boo1;
};
private:
};
int main()
{
foo2 object;
cout << /* ??? */ ;
}
Run Code Online (Sandbox Code Playgroud)
首先,类中的代码结构是否存在任何问题,其次,我应该在注释的位置放置在int main()中初始化的foo2对象中显示字符串a?