tkinter:按钮颜色不更新

时间:2017-07-14 14:44:16

标签: python button tkinter colors updates

我的GUI的button3正在调用一个需要很长时间来计算内容的函数。所以在此期间我想更改按钮文本和颜色:

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

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

1 个答案:

答案 0 :(得分:1)

在长时间计算期间,您的按钮可能仍处于活动状态。因此,您可能希望将其activeforeground颜色设置为红色:

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

activeforeground =按钮所用的前景色   活性。默认值是系统特定的。 (activeForeground /背景)

(Tkinter Button documentation)