Skip to main content
 首页 » 编程设计

python之让用户查看 Tkinter 中是否禁用了某个条目

2024年10月17日852php

有没有办法明显地表明一个条目被禁用了?禁用条目时唯一发生的事情是您不能再点击它,但它的外观不会改变。

我尝试将背景更改为较暗的背景,但如果条目被禁用,它也不会改变。

def blockentry(evento): 
    if self.addVotoFrameEntry2["state"] == NORMAL: 
        self.addVotoFrameEntry2["state"] = DISABLED 
    elif self.addVotoFrameEntry2["state"] == DISABLED: 
        self.addVotoFrameEntry2["state"] = NORMAL 
self.addVotoFrameCheck = Checkbutton(self.addVotoFrame, text="Oggi", font=("Helvetica 11"), variable=var) 
self.addVotoFrameCheck.pack(anchor=SW) 
self.addVotoFrameCheck.bind("<Button-1>", blockentry) 
self.addVotoFrameEntry2 = Entry(self.addVotoFrame, width=10) 
self.addVotoFrameEntry2.pack(pady=(0, 10)) 

请您参考如下方法:

Entry不仅有background还有disabledbackground, insertbackground, readonlybackground , selectbackground - 所以你必须使用正确的变量:)

查看更多信息 Entry

顺便说一句:文本颜色是foreground、disabledforeground等