2017-04-03 3 views
0

Dans le cadre d'une fonction dans un script Python d'un PuiQt5 Gui j'ai le code suivant:Pyqt QtCore.QTimer() .timeout.connect (self.function) erreur [manquant 1 argument de position requis: 'Form']

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) 

Je reçois l'erreur:

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

Quand je change le code:

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

Je reçois l'erreur:

argument 1 has unexpected type 'NoneType'

Comment puis-je résoudre ce problème?

Merci

Répondre

1

Vous aurez besoin d'utiliser soit lambda: self.function(Form) ou functools.partial(self.function, Form) pour obtenir un appelable qui ne nécessite pas un argument, mais peut encore être appelé plus tard par QTimer.