无法在Tkinter中更改按钮的颜色

时间:2018-11-17 10:46:42

标签: python tkinter

我无法使用fg和bg更改按钮的颜色。我收到此错误:CoinModel

_tkinter.TclError: unknown option "-fg"

1 个答案:

答案 0 :(得分:2)

发生这种情况的原因是因为您使用的是ttk.Button而不是tk.Buttonfgbg之类的选项是not supported by ttk。相反,您将必须使用Style选项并根据需要进行配置。这是一个例子。

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

style = ttk.Style()
style.configure("TButton", foreground="blue", background="orange")

myButton = ttk.Button(text="Scrape", style="TButton")
myButton.grid()

root.mainloop()

enter image description here

相关问题