Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Radiobutton不运行定义_Python_User Interface_Radio Button_Tkinter - Fatal编程技术网

Python Radiobutton不运行定义

Python Radiobutton不运行定义,python,user-interface,radio-button,tkinter,Python,User Interface,Radio Button,Tkinter,我正在为我的程序使用GUI。代码如下所示: lijst=[] def setValueTrue(): del lijst[0:len(lijst)] e2="True" lijst.append(e2) print lijst[0] def setValueFalse(): del lijst[0:len(lijst)] e2="False" lijst.append(e2) print lijst[0] lijst1=[] d

我正在为我的程序使用GUI。代码如下所示:

lijst=[]
def setValueTrue():
    del lijst[0:len(lijst)]
    e2="True"
    lijst.append(e2)
    print lijst[0]

def setValueFalse():
    del lijst[0:len(lijst)]
    e2="False"
    lijst.append(e2)
    print lijst[0]

lijst1=[]
def setValueTrue1():
    del lijst1[0:len(lijst1)]
    e2="True"
    lijst1.append(e2)

def setValueFalse1():
    del lijst1[0:len(lijst1)]
    e2="False"
    lijst1.append(e2)


root = Tk()
var = IntVar()
R1 = Radiobutton(root, text="Option 1", variable=var, value=1,
                  command=setValueTrue())
R1.pack(anchor = W)
R2 = Radiobutton(root, text="Option 2", variable=var, value=2,
                  command=setValueFalse())
R2.pack(anchor = W)
R3 = Radiobutton(root, text="Option 3", variable=var, value=3,
                  command=setValueTrue1())
R3.pack(anchor = W)

R4 = Radiobutton(root, text="Option 4", variable=var, value=4,
                  command=setValueFalse1())
R4.pack(anchor = W)

b=Button(root, text='Quit', command=root.quit)
b.pack()
b=Button(root, text='Oke', command=lambda:tekenGraaf("OutputB1.txt",25,0.8,dimensies=3,kleur=str(lijst[0]),groepen=str(lijst1[0])))
b.pack()
mainloop()

我有4个单选按钮。它们使用定义创建值true或false。我想在我的“大”定义中使用这个值。但是当我单击单选按钮时,defs(setValueTrue等)不会执行。只有在我运行程序时,单选按钮才会运行def。因此,list和list1的值会自动变为false和false。有人知道为什么单选按钮没有运行代码。

命令选项引用函数。执行
command=setValueTrue()
操作时,您正在调用函数,并将函数的结果提供给
command
属性。结果是
None
,因此没有与按钮关联的命令

解决方法是删除括号:

R1 = Radiobutton(..., command=setValueTrue, ...)

谢谢,这就是我需要的