gpt4 book ai didi

python - Tkinter 反转单选按钮的颜色

转载 作者:行者123 更新时间:2023-12-01 01:19:01 28 4
gpt4 key购买 nike

尝试在选择单选按钮后反转其颜色。目前,当未选择按钮时,背景为灰色,前景为白色。选择后,背景变为白色,但前景也保持白色。我希望能够在选择前景时更改其颜色。

import tkinter as tk
root = tk.Tk()
v = tk.IntVar()
v.set(0)

periods = [
("Current"),
("-1"),
("-2"),
("1 Week"),
("2 Weeks"),
("1 Month"),
("3 Months"),
]
def ShowChoice():
print (v.get())

for val, period in enumerate(periods):
tk.Radiobutton(root,
text=period,
indicatoron =0,
padx=20,
variable=v,
command=ShowChoice,
value=val,
background='gray15',
foreground='snow',).pack(side=tk.LEFT)
root.mainloop()

这就是按钮当前的样子:

White bg on selected radiobutton

提前致谢

最佳答案

一切都是

selectcolor='gray25'

单选按钮的选项现在看起来像这样:

for val, period in enumerate(periods):
tk.Radiobutton(root,
text=period,
indicatoron =0,
padx=20,
variable=v,
command=ShowChoice,
value=val,
background='gray15',
foreground='snow',
selectcolor='gray25').pack(side=tk.LEFT)
root.mainloop()

结果是这样的: enter image description here

关于python - Tkinter 反转单选按钮的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54020357/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com