我正在用Tkinter制作一个GUI程序问题。什么我想做的是画2个复选框和一个按钮。根据用户的输入,下一步应该进行。我的部分代码如下所示:
CheckVar1 = IntVar()
CheckVar2 = IntVar()
self.C1 = Checkbutton(root, text = "C Classifier", variable = CheckVar1, onvalue = 1, offvalue = 0, height=5,width = 20).grid(row=4)
self.C2 = Checkbutton(root, text = "GClassifier", variable = CheckVar2, onvalue = 1, offvalue = 0, height=5, width = 20).grid(row=5)
self.proceed1 = Button(root,text = "\n Proceed",command = self.proceed(CheckVar1.get(),CheckVar2.get())).grid(row=6)
# where proceed prints the combined values of 2 checkboxes
我得到的错误是典型的,即两个选中复选框的默认值被打印出来,然后就没有进一步的输入。我得到的错误是NullType对象不可调用。在
我在网上搜索了一下,我想答案是和兰姆达事件或咖喱有关。在
请帮忙。。在
{{{1}你可能想让一个的函数。您可以使用lambda或通过将调用包装在一个简短的回调函数中来解决这个问题。例如,将最后一行替换为:
这是很典型的。记住:当您在Tkinter中看到一个名为
command
的变量时,它寻找的是一个函数,而不是一个值。在编辑:请明确:您得到的是“NullType Object is not callable”,因为您已经将
command
设置为等于对self.proceed
(即NullType对象)的单个调用的返回值。self.proceed
是一个函数,但它的返回值不是。您需要的是将command
设置为调用self.proceed
的函数。在正如petermilley所说,
command
选项需要对函数的引用(即:给它一个函数名称(即:没有括号)。不要试图“内联”一些东西,创建一个特殊的函数。您的代码将更易于理解和维护。在相关问题 更多 >
编程相关推荐