You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改ttk Radiobutton指示器颜色?已尝试方案无效求助

自定义ttk Radiobutton指示器与边框颜色失败,求解决方案及样式逻辑解释

我想修改ttk Radiobutton的指示器和边框颜色,目标效果是:选中时边框和指示器为蓝色,未悬停状态下边框和指示器也保持蓝色。但按照相关方案操作后完全没效果,当前按钮选中时指示器是蓝色、未悬停时是黑色,和默认样式没区别。我试过调整style.configure参数,也搜过其他解决方案,都没成功。

以下是我尝试的代码:

from tkinter import *
import tkinter.ttk as ttk
from PIL import Image, ImageTk

root = Tk()
root.geometry('768x570')
root.title('euy')

root_frame = Frame(root)
root_frame.pack(fill=BOTH, expand=1, padx=32)

common_fg = '#FF0'
common_bg = '#0672D9'

style = ttk.Style()
style.configure('C.TRadiobutton', background=common_fg,
                indicatorcolor=common_fg)
style.map('C.TRadiobutton',
          indicatorcolor=[('selected', common_bg),
                          ('pressed', '#FF0')]
          )
rb_step2 = ttk.Radiobutton(root_frame, style='C.TRadiobutton')
rb_step2.pack()

当前效果如图:
单选按钮当前效果

希望有人能给出可行的解决方案,同时解释一下tkinter框架在自定义ttk样式时的行为逻辑,比如为什么我的配置没生效?

内容的提问来源于stack exchange,提问作者hol'Up

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 12:17:37