无法更改按钮颜色。ttk

问题描述 投票:0回答:1

使用 tkinter.ttk 不会改变按钮背景的颜色

将 tkinter 导入为 tk 将 tkinter.ttk 导入为 ttk

root = tk.Tk()

风格 = ttk.Style() style.configure(“TButton”,前景=“蓝色”,背景=“橙色”)

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

root.mainloop()

enter image description here

python ttk tkinter-button
1个回答
0
投票

在 ttk 中,对于某些系统,如果您想更改按钮的颜色,则无法使用默认主题。如果你使用类似 -

import tkinter as tk
from tkinter import ttk 
root = tk.Tk()
style = ttk.Style()
style.theme_use('alt')

style.configure("TButton", foreground="blue", background="orange")
myButton = ttk.Button(text="Scrape", style="TButton") myButton.grid()
root.mainloop()

它应该允许您自由更改按钮前/背景。这是 ttk 按钮的一个相对论已知问题,某些默认主题会阻止颜色的更改等

© www.soinside.com 2019 - 2024. All rights reserved.