小编nay*_*aan的帖子

如何在 Python Tkinter 中更改条目小部件边框颜色

我正在开发一个具有条目小部件的程序。当用户单击按钮并且该条目小部件为空时,程序会将其边框颜色更改为红色。但是当我尝试时,边框保持相同的颜色,即黑色。

这是代码:

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)

python tkinter border widget tkinter-entry

3
推荐指数
1
解决办法
2万
查看次数

如何在C++中从嵌套类调用变量

所以我的代码有点像这样

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?

c++ class object nested-class c++11

1
推荐指数
1
解决办法
60
查看次数

标签 统计

border ×1

c++ ×1

c++11 ×1

class ×1

nested-class ×1

object ×1

python ×1

tkinter ×1

tkinter-entry ×1

widget ×1