在选择单选按钮时尝试使其颜色反转。当前,当未选择按钮时,背景为灰色,前景为白色。选择后,背景变为白色,但前景也保持白色。我希望能够在选择前景时更改其颜色。
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()
这是当前按钮的外观:
预先感谢
答案 0 :(得分:2)