![](/img/trans.png)
[英]is there a way to set a default button color (on click) for tkinter?
[英]tkinter styling with state map: How to set the default text color in a button?
我正在嘗試使用樣式 map 設置按鈕文本的樣式,但不知道如何設置默認顏色。 我知道我必須使用不同的狀態,如果按鈕被按下或禁用,我可以更改文本顏色,但我找不到默認名稱 state。
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
style = ttk.Style()
style.map('TButton',
foreground=[
('disabled', 'yellow'),
('pressed', 'red'),
('active', 'blue')
]
)
ttk.Button(root, text = 'Button').pack(pady = 10)
root.mainloop()
根據文檔: https://docs.python.org/3/library/tkinter.ttk.html#widget-states
有 9 個不同的狀態。 活動禁用焦點按下選擇只讀備用背景無效
您可以簡單地設置默認顏色
style.configure("TButton",foreground="pink")
這為您的小部件設置了文本顏色。 每當它輸入一個特殊的 state 就像選擇或你設置小部件只讀代碼等。它應用你的 state 值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.