我不能让我的程序改变状态栏的文本按钮点击。我一直在
上的"TypeError: argument 1 has unexpected type 'NoneType'"
错误self.closeButton.clicked.连接(自我过程('文本')'。
我不知道该怎么办了
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QLineEdit,
QPushButton
from PyQt5.QtGui import QIcon
class App(QMainWindow):
def process(self):
self.statusBar.showMessage('online')
def __init__(self):
super().__init__()
self.title = 'Red Queen v0.4'
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.statusBar().showMessage('Offline')
self.showMaximized()
self.setStyleSheet("background-color: #FFFFFF;")
self.textbox = QLineEdit(self)
self.textbox.move(500, 300)
self.textbox.resize(350, 20)
self.textbox.setStyleSheet("border: 3px solid red;")
self.setWindowIcon(QIcon('Samaritan.png'))
text = QLineEdit.text(self.textbox)
self.closeButton = QPushButton('process', self)
self.closeButton.clicked.connect(self.process('text'))
self.closeButton.show()
self.show()
self.textbox.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
换行:
到
^{pr2}$您需要将函数本身作为参数传递,而不是函数调用的结果(因为您的方法不包含return语句,})。在
self.process()
返回{如果您想让
process
方法接受一个参数,您必须首先按照Avión的建议对其进行更改:但将连接到点击信号的线路改为:
需要lambda表达式将可调用对象传递给connect()。在
将
process
函数更改为:现在当你调用函数时
self.closeButton.clicked.connect(self.process('text'))
它将接收文本并打印它。在相关问题 更多 >
编程相关推荐