以下代码允许用户只选择一个单选按钮。例如,如果用户选择 Type II 按钮,然后单击 Type III 按钮,则先前的选择将消失。
from tkinter import *
root = Tk()
radiobutton_variable = IntVar()
Radiobutton(root, text="Type II", variable = radiobutton_variable, value = 1).grid(row = 0, column = 0)
Radiobutton(root, text="Type III", variable = radiobutton_variable, value = 2).grid(row = 0, column = 1)
Radiobutton(root, text="Type IV", variable = radiobutton_variable, value = 3).grid(row = 1, column = 0)
Radiobutton(root, text="Type V", variable = radiobutton_variable, value = 4).grid(row = 1, column = 1)
mainloop()
如果我对检查按钮小部件使用相同的代码,我会收到错误消息:
TclError: unknown option "-value"
有人知道如何解决这个问题吗?
鸿蒙传说
MMMHUHU
慕尼黑5688855
相关分类