2017-04-03 443 views
0

作爲PyQt5 Gui的python腳本中的函數的一部分,我有以下代碼:Pyqt QtCore.QTimer().timeout.connect(self.function)error [缺少1個必需的位置參數:'窗體']

def link_info(self, Form): 
    self.timer = QtCore.QTimer() 
    self.timer.stop 
    self.ip=self.lineEdit_ip.text() 
    self.port=int(self.lineEdit_2.text()) 
    self.function(Form) 
    print('here') 
    self.timer.timeout.connect(self.function) 
    self.timer.start(5000) 

我收到錯誤:

function() missing 1 required positional argument: 'Form'

當我的代碼更改爲:

self.timer.timeout.connect(self.function(Form)) 

我得到的錯誤:

argument 1 has unexpected type 'NoneType'

我該如何解決這個問題?

感謝

回答

1

你需要爲使用lambda: self.function(Form)functools.partial(self.function, Form)得到調用不需要參數,但仍可以在通過QTimer以後的時間被調用。

相關問題