2017-08-03 6 views
-1

ボタンクリックでステータスバーのテキストを変更するプログラムができません。私は 'self.closeButton.clicked.connect(self.process(' text '))'に「ボタンクリック時にPyqtステータスバーのテキストを変更する

"TypeError: argument 1 has unexpected type 'NoneType'"というエラーが発生しています。 私は

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

信号をスロットに接続する必要があり、self.process( 'text')はスロット/呼び出し可能ではありません。また、あなたの例は最小限ではありません。 – Trilarion

答えて

2

変更行:

self.closeButton.clicked.connect(self.process) 

self.closeButton.clicked.connect(self.process('text')) 

あなたのメソッドがリターンを含んでいないので、引数ではなく、関数呼び出し(の結果としての機能自体を渡す必要があります声明、self.process()Noneを返す)。

引数を受け入れるprocess方法のためにしたい場合は、あなたが最初アビオンがすでに示唆したように、それを変更する必要があります。

def process(self, text): 
    self.statusBar.showMessage(text) 

をそれにクリックされた信号に接続している行を変更:

self.closeButton.clicked.connect(lambda: self.process('offline')) 

lambda式は、callableオブジェクトをconnect()に渡すために必要です。

1

もう何をするか分からない変更process関数へ:

def process(self, text): 
    self.statusBar.showMessage(text) 

あなたが機能 self.closeButton.clicked.connect(self.process('text'))を呼び出すとき今では、テキストを取ると、それを印刷します。

+0

大丈夫ですが、これは修正されましたが、終了コマンドがリンクされていないにもかかわらず、ボタンをクリックした後にウィンドウ自体が閉じられるようになりました。 – user3657752

関連する問題