参数 1 有意外的类型“NoneType"?

Argument 1 has unexpected type #39;NoneType#39;?(参数 1 有意外的类型“NoneType?)
本文介绍了参数 1 有意外的类型“NoneType"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的 PyQt 按钮操作有问题.我想发送一个带有函数的字符串,但我收到了这个错误:

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:参数 1 具有意外类型NoneType"

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 和 ekhumoro 它需要一个可调用的函数.在这种情况下,您应该将该参数替换为 lambda: mixCocktail("string")AND ALSO 不要使用 str 它是 python 内置数据类型,我已将其替换为 _str

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_())

关于 lambda 函数的更多信息:什么是 lambda(函数)?

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

这篇关于参数 1 有意外的类型“NoneType"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Multiprocessing on Windows breaks(Windows 上的多处理中断)
How to use a generator as an iterable with Multiprocessing map function(如何将生成器用作具有多处理映射功能的可迭代对象)
read multiple files using multiprocessing(使用多处理读取多个文件)
Why does importing module in #39;__main__#39; not allow multiprocessig to use module?(为什么在__main__中导入模块不允许multiprocessig使用模块?)
Trouble using a lock with multiprocessing.Pool: pickling error(使用带有 multiprocessing.Pool 的锁时遇到问题:酸洗错误)
Python sharing a dictionary between parallel processes(Python 在并行进程之间共享字典)