其他类呼叫模块

问题描述:

所以我有一个close()方法,当用户单击关闭按钮时被调用。 close方法如下:其他类呼叫模块

def close(self): 
    ThreadedClient.endApplication() 

    root.destroy() 

close()方法在GUI()类中。 close方法需要调用ThreadedClient类中的endApplication()方法。但相反,它给了我这个错误:

TypeError: unbound method endApplication() must be called with ThreadedClient instance as first argument (got nothing instead) 

这可能是一个简单的解决方案,但我只是不知道如何解决它。任何帮助表示赞赏!

+0

这是使用Tkinter的? –

您需要提问的问题是其中ThreadedClient需要有.endApplication()对它进行调用。

一旦你有对它的引用(假设你存储参考在self

def close(self): 
    self.threaded_client.endApplication() 
    # ... 

显然,endApplication()是一个实例的方法,但ThreadedClient类。您需要为其提供您想要结束的ThreadedClient的实际实例。

举例来说,如果别的地方你创建了...

foo = ThreadedClient() 

再后来就你一个线程客户端就需要调用...

foo.endApplication()