Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 按钮对象更改为偶数对象_Python_Tkinter_Lambda - Fatal编程技术网

Python 按钮对象更改为偶数对象

Python 按钮对象更改为偶数对象,python,tkinter,lambda,Python,Tkinter,Lambda,我正在创建按钮,然后将它们作为参数传递给我创建的一个名为(placement)的函数,但当我将它们作为参数运行并尝试打印此输入的类型时,它们会成为事件对象,我不明白为什么会发生这种情况,我需要它们保持为按钮对象,因为我想在单击按钮后更改其文本 for column in range(self.column + 1): new_button = Button(new_frame, text = ' ', height = 10, width = 20) new_button.gri

我正在创建按钮,然后将它们作为参数传递给我创建的一个名为(placement)的函数,但当我将它们作为参数运行并尝试打印此输入的类型时,它们会成为事件对象,我不明白为什么会发生这种情况,我需要它们保持为按钮对象,因为我想在单击按钮后更改其文本

for column in range(self.column + 1):
    new_button = Button(new_frame, text = ' ', height = 10, width = 20)
    new_button.grid(row = r, column = c)
    new_button.bind('<Button-1>', func = lambda x=new_button: self.placement(x))

def placement(self, button):
    print(type(button))
    if self.current == 1:
        button.config(text = 1)
        self.current = 2
    else:
        button.config(text = 2)
        self.current = 1
范围内的列(self.column+1)的
:
新建按钮=按钮(新建框架,文本='',高度=10,宽度=20)
新建按钮网格(行=r,列=c)
新建按钮.bind(“”,func=lambda x=new按钮:self.placement(x))
def放置(自身,按钮):
打印(类型(按钮))
如果self.current==1:
button.config(text=1)
自身电流=2
其他:
button.config(text=2)
自电流=1

bind函数需要一个
事件
参数,因此您必须将代码更改为:

new_button.bind('<Button-1>', func = lambda event, x=new_button: self.placement(x))
new_button.bind(“”,func=lambda事件,x=new_button:self.placement(x))

bind函数需要一个
事件
参数,因此您必须将代码更改为:

new_button.bind('<Button-1>', func = lambda event, x=new_button: self.placement(x))
new_button.bind(“”,func=lambda事件,x=new_button:self.placement(x))