【发布时间】:2017-08-03 21:53:28
【问题描述】:
我无法让我的程序在单击按钮时更改状态栏文本。我不断得到
"TypeError: argument 1 has unexpected type 'NoneType'"'self.closeButton.clicked.connect(self.process('text'))' 上的错误。
我不知道该怎么办了
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_())
【问题讨论】:
-
您必须将信号连接到插槽,并且 self.process('text') 不是插槽/可调用的。此外,您的示例远非最小。