我只想创建一个带有两个选项的 Tkinter Radiobutton:一次点击 = select 另一次点击 = unselected。我怎样才能做到这一点?

I want to create only one Tkinter Radiobutton with two options: one click = select another click = unselected. How can I do this?

Radiobutton(register_win, variable=var, value=1, bg="#a1c4cc", activebackground="#a1c4cc").place(x=15, y=249) 

在这段代码中我可以select但我不能取消select

如评论中所述,除非选择了组中的另一个单选按钮,否则单选按钮将保持选中状态。 下面的示例显示了如何使用单选按钮和复选按钮。

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

w = tk.IntVar()
w.set(1)

rbtn1 = tk.Radiobutton(root,text="On",variable=v,value=1)
rbtn1.grid()
rbtn2 = tk.Radiobutton(root,text="Off",variable=v,value=0)
rbtn2.grid()

chkbtn = tk.Checkbutton(root,text="Press Me",variable=w)
chkbtn.grid()


root.mainloop()

请注意,我通过将变量 w 设置为 1,将 Checkbutton 设置为在程序启动时被选中。