[英]Cannot change color of button in Tkinter
我无法使用fg和bg更改按钮的颜色。 我收到此错误: _tkinter.TclError: unknown option "-fg"
_scrape_btn = ttk.Button(_mainframe, text='Scrape!', command=save, fg='blue')
_scrape_btn.grid(row=2, column=0, sticky=(N,E), pady=2)
_compress_btn = ttk.Button(_mainframe, text='Compress!', command=compress)
_compress_btn.grid(row=2, column=1, sticky=W, pady=2)
发生这种情况的原因是因为您使用的是ttk.Button
而不是tk.Button
。 ttk不支持 fg
, bg
类的选项。 相反,您将必须使用“ 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.