python - tkinter:按钮颜色不更新

标签 python button tkinter colors updates

我的 GUI 的 Button3 正在调用一个函数,该函数需要很长时间才能计算内容。所以与此同时,我想更改按钮文本和颜色:

self.button3.config(foreground='red')
self.button3['text'] = 'PLEASE WAIT ...'
self.button3.update_idletasks()

按钮的文本确实发生了变化,但颜色保持不变。为什么?

最佳答案

在长时间计算过程中,您的按钮可能保持在事件状态。因此,您可能需要将其 activeforeground 颜色设置为红色:

self.button3.config(activeforeground='red')

activeforeground = What foreground color to use when the button is active. The default is system specific. (activeForeground/Background)

(Tkinter Button documentation)

关于python - tkinter:按钮颜色不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45105795/

相关文章:

html - 使用 Bootstrap 在 "img-responsive"div 顶部添加按钮

python - 获取 askopenfilename 选择的字符串中的文件目录

python - 什么会导致 Tkinter/Python 中打开的文件对话框窗口在用户选择文件后关闭得非常慢?

python - 我的代码在 pandas 中运行正常,但在 modin 中运行不正常

python - 修改 Python 3.1 中的特定数组元素

python - 如何在 python 中用数字对之间的破折号格式化 MD5 哈希?

python - dataframe.sort_values() 是如何修改索引的

asp.net - 如何隐藏 FileUpload 控件的 "TextBox"?

c# - 单击按钮(动态创建的按钮)获取对象/项目 - 堆栈面板

python - 如何使 tkinter Canvas 多边形透明?