Argument 1 has unexpected type 'NoneType'?

41,765

Solution 1

As suggested by user3030010 and ekhumoro it expects a callable function. In which case you should replace that argument with lambda: mixCocktail("string") AND ALSO don't use str it's a python built-in datatype I have replaced it with _str

import sys
from PyQt5.QtWidgets import QApplication, QPushButton, QAction
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtGui import *
from PyQt5.uic import *
app = QApplication(sys.argv)
cocktail = loadUi('create.ui')
def mixCocktail(_str):
      cocktail.show()
      cocktail.showFullScreen()
      cocktail.lbl_header.setText(_str)
widget = loadUi('drinkmixer.ui')
widget.btn_ckt1.clicked.connect(lambda: mixCocktail("string"))
widget.show()
sys.exit(app.exec_())

More about lambda functions: What is a lambda (function)?

Solution 2

instead of this

widget.btn_ckt1.clicked.connect(mixCocktail("string"))

write

widget.btn_ckt1.clicked.connect(lambda:mixCocktail("string"))

Share:
41,765

Related videos on Youtube

Darkdrummer
Author by

Darkdrummer

Updated on May 16, 2021

Comments

  • Darkdrummer
    Darkdrummer about 2 years

    I have a problem with my PyQt button action. I would like to send a String with the Function but I got this Error:

    TypeError: argument 1 has unexpected type 'NoneType'

    import sys
    from PyQt5.QtWidgets import QApplication, QPushButton, QAction
    from PyQt5.QtCore import QObject, pyqtSignal
    from PyQt5.QtGui import *
    from PyQt5.uic import *
    app = QApplication(sys.argv)
    cocktail = loadUi('create.ui')
    def mixCocktail(str):
          cocktail.show()
          cocktail.showFullScreen()
          cocktail.lbl_header.setText(str)
    widget = loadUi('drinkmixer.ui')
    widget.btn_ckt1.clicked.connect(mixCocktail("string"))
    widget.show()
    sys.exit(app.exec_())
    
    • user3030010
      user3030010 over 6 years
      From looking at some example online, it looks like it expects a callable function. In which case you should replace that argument with lambda: micCocktail("string")
  • ekhumoro
    ekhumoro over 6 years
    str is not a keyword - it's a built-in type.
  • ekhumoro
    ekhumoro over 6 years
    This answer is completely wrong. The correct solution was given in the comment by user3030010.
  • harshil9968
    harshil9968 over 6 years
    made it wiki as it was from both of your assistance.

Related