tkinter - 更改禁用条目小部件的颜色 [英] tkinter - Change color of a disabled entry widget

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

问题描述

有没有办法在 python 中更改禁用条目小部件的颜色?

Is there a way that I could change a color of disabled entry widget in python?

x = tk.Entry(parent)
x.configure({"background": "gray24"})
x.configure({"fg": "white"})
x.configure({"state": "disable"})

以上代码仅在小部件的状态"为正常"时有效.

The code above only works when the "state" of the widget is "normal".

推荐答案

设置入口小部件的 disabledbackground 属性.

Set the entry widget's disabledbackground attribute.

x.configure({"disabledbackground": "newcolour"})

其中 "newcolour" 是您希望在禁用条目小部件时看到的颜色.您还可以将 disabledforeground 用于前景色,而不是背景色.

Where "newcolour" is the colour you want to see when the entry widget is disabled. You can also use disabledforeground for foreground colours, rather than background colours.

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

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