Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.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-Tkinter事件中从类外部调用方法_Python_Tkinter - Fatal编程技术网

在Python-Tkinter事件中从类外部调用方法

在Python-Tkinter事件中从类外部调用方法,python,tkinter,Python,Tkinter,我想在另一个类中调用一个方法,并在Python中单击按钮时对父类进行更改。解释;在Tkinter可视化编程中,我单击按钮更改主窗口,但无法使用其他类方法更改主窗口中的属性 我得到下面的错误消息 Tkinter回调回溯中出现异常(最近一次调用为last): 文件“/usr/lib/python3.5/tkinter/uinit uu.py”,第1553行,在_ 召唤_ return self.func(*args)TypeError:buton_goster()缺少1个必需的位置参数:“事件”

我想在另一个类中调用一个方法,并在Python中单击按钮时对父类进行更改。解释;在Tkinter可视化编程中,我单击按钮更改主窗口,但无法使用其他类方法更改主窗口中的属性

我得到下面的错误消息

Tkinter回调回溯中出现异常(最近一次调用为last):

文件“/usr/lib/python3.5/tkinter/uinit uu.py”,第1553行,在_ 召唤_

return self.func(*args)TypeError:buton_goster()缺少1个必需的位置参数:“事件”


这是测试课

class Test(Frame):

    countshow = 0

    ...
    def new_Button(self):
        self.nesne = Butonol()
        self.but= Button(self.mainFrame,text = self.nesne.text)
        self.but.bind('<Button-1>',Butonol.buton_goster)
        self.but.bind('B1-Motion>',self.label_tasi)
        self.but.pack(side = LEFT,anchor = N)
        Butonol.butonsay = Butonol.butonsay + 1
        Butonol.butonliste.append(self.but)
类测试(框架):
countshow=0
...
def新建按钮(自身):
self.nesne=丁醇()
self.but=按钮(self.mainFrame,text=self.nesne.text)
self.but.bind(“”,Butonol.buton\u goster)
self.but.bind('B1-Motion>',self.label_-tasi)
self.but.pack(侧=左,锚=N)
Butonol.butonsay=Butonol.butonsay+1
Butonol.butonliste.append(self.but)
错误是正确的, 绑定时,不传递事件,只需添加函数指针


如果buton_goster不需要“事件”,则应将其删除或在调用函数时提供事件作为输入

bind(“”,Butonol.buton\u goster)
更改为
bind(“”,self.buton.buton\u goster)
。“buton\u ol”方法在Butonol类中,因此当我这样做时,我希望在测试类中使用“buton\u goster”方法。我想从Butonol类调用buton_goster方法。删除事件参数时出现错误
class Test(Frame):

    countshow = 0

    ...
    def new_Button(self):
        self.nesne = Butonol()
        self.but= Button(self.mainFrame,text = self.nesne.text)
        self.but.bind('<Button-1>',Butonol.buton_goster)
        self.but.bind('B1-Motion>',self.label_tasi)
        self.but.pack(side = LEFT,anchor = N)
        Butonol.butonsay = Butonol.butonsay + 1
        Butonol.butonliste.append(self.but)