单选按钮在 tkinter

Radiobutton IN tkinter

我正在为一个简单的测验创建一个 GUI,我希望在 radiobutton 中检查我的答案。但问题是我不能标记或取消标记它,它总是设置标记。我的代码是

R1=Radiobutton(win,text= 'option1',command =sel1)

我的函数 sel1 如下:

 def sel1():
      global ans
      ans = 1

据我所知from the docs the radiobutton is used to select one out of many, whcih as I understand will always require one button to be marked. It's possible you need CheckButton

编辑:事实证明问题是为上面链接的文档中提到的所有单选按钮设置公共变量。