2017-11-20 1 views
0

Ich bekomme zweimal einen Fehler bei der Verwendung von * Args in meinem Maingui (PyQt5) Skript nicht sicher, warum. Was mache ich nicht Python/Pygat5 Stil?PyQt5 - TypeError "NoneType" bei der Verwendung von * Args w/o functools

Erster Versuch:

Kodierzeilen, die den Fehler gab, als aus der GUI genannt:

def createActions(self): 
    ... 
    self.lineEdit.returnPressed.connect(self.updateUi('buttons')) 

Der Fehler:

Traceback...(snippet) 
... 
self.lineEdit.returnPressed.connect(self.updateUi('buttons')) 
TypeError: argument 1 has unexpected type 'NoneType' 

Es ist vielleicht nicht eine Funktion sein ... so Ich änderte es zu meinem zweiten Versuch als Mark Summerfield beschrieben in RapidGUI Programmierung mit Python und PyQt, Seite 133:

def createActions(self): 
    ... 
    self.lineEdit.returnPressed.connect(functools.partial(self.updateUi, 'buttons')) 

def updateUi(self, *args): 

     if args == 'color_update': 
      color = self.colorCh2comboBox.currentText() 

      if color == 'Violet': 
       print '%s is purple' % color 
      else: 
       print color 

     elif args== 'buttons': 

      try: 
       print 'yes' 
       ... 
      except: 
       print "no" 
       ... 
     else: 
      print "Unknown action : %s" % args 

result: "Unknown action : buttons

Im dritten Versuch habe ich versucht:

def updateUi(self, *args): 

    argument = str(args) # just to be sure I'll parse a string and not something else. 
    ...etc... # as above. 

Was könnte es sonst sein?

Antwort

0

Also was ich als nächstes getan habe ... mit type überprüfen was mit args los war.

Mein Code:

def updateUi(self, *args): 

     argument = str(args) 
     print type(argument), type(args) 

Ergebnis:

<type 'str'> <type 'tuple'> 
yes # from the try... print 'yes' 
no # from the except.. print 'no' 

So..args war ein Tupel (doh!).

-Code geändert, wie unten und es funktioniert jetzt :-)

def updateUi(self, *args): 

     argument = str(args) 
     print type(argument), type(args) 

     for item in args: 
      if color == 'Violet': 
       color = ...etc. 
Verwandte Themen