tkinter ttk条目小部件-disabledforeground [英] tkinter ttk Entry widget -disabledforeground

查看:221
本文介绍了tkinter ttk条目小部件-disabledforeground的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将状态设置为禁用 ttk.Entr 小部件中单词的颜色。 c>,我查阅了手册,有一个名为 disabledforeground 的选项,所以我写了一个如下的测试代码段:(顺便说一句,我在Python 2.7下)

I was trying to change the color of the words in my ttk.Entr widget when I set the state to disabled, I looked up the manual, there's an option called disabledforeground, so I wrote a test snippet as below: (BTW, I'm under Python 2.7)

from Tkinter import *
from ttk import *

root=Tk()

style=Style()
style.configure("TEntry",disabledforeground='red')

entry_var=StringVar()
entry=Entry(root,textvariable=entry_var,state='disabled')
entry.pack()

entry_var.set('test')

mainloop()

但是结果显示测试的颜色没有变化,知道有什么问题吗?

But the result shows no change in the color of "test", any idea what's wrong?

推荐答案

尝试使用 Style.map 而不是配置

from Tkinter import *
from ttk import *

root=Tk()

style=Style()
style.map("TEntry",
          foreground=[("active", "black"), ("disabled", "red")]
          )

entry_var=StringVar()
entry=Entry(root,textvariable=entry_var,state='disabled')
entry.pack()

entry_var.set('test')

mainloop()

这篇关于tkinter ttk条目小部件-disabledforeground的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆