1
でイベントにボタンを接続できません:は、私は関数にボタンを接続しようとしていると、私は次のエラーを取得するPyQtは
QObject.connect(b1,SIGNAL("clicked()"),GetBestMatch)
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): first argument of unbound method must have type 'QObject'
これは私がそれを与えているダウン書かれている接続コードでありますエラー:
b1.clicked.connect(GetBestMatch)
:私はまた、次のコードで接続しようとした
QObject.connect(b1,SIGNAL("clicked()"),GetBestMatch)
エラーを取得します。
b1.clicked.connect(GetBestMatch)
AttributeError: 'NoneType' object has no attribute 'clicked'
私は間違って何をしているのか分かりません。
ラベルとボタンでグリッドを作成できますが、ボタンを機能に接続することはできません。これはGUIコードです
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def MainWindow():
app = QApplication(sys.argv)
screen_resolution = app.desktop().screenGeometry()
width, height = screen_resolution.width(), screen_resolution.height()
win = QWidget()
win.adjustSize()
grid=QGridLayout()
grid.setRowStretch(0, 1)
grid.setRowStretch(1, 1)
grid.setRowStretch(5, 1)
for i in range(0,5):
for j in range(0,4):
if i==0 and j==2:
l1=grid.addWidget(QLabel("Choose an option:"),i,j, 2, 2)
if i==2 and j==1:
b1=grid.addWidget(QPushButton("Get Best Match"),i,j)
elif i==2 and j==2:
b2=grid.addWidget(QPushButton("Button 2"),i,j)
elif i==2 and j==3:
b3=grid.addWidget(QPushButton("Button 3"),i,j)
b5=grid.addWidget(QLabel(""),3,4)
b4=grid.addWidget(QPushButton("Button 4"),2,4)
win.setLayout(grid)
win.setGeometry(100,100,width//2,height//2,)
win.setWindowTitle("Information on all tracking buses")
win.show()
win.setStyleSheet("""
.QPushButton {
height: 30px ;
width: 20px ;
}
.QLabel {
qproperty-alignment: AlignCenter;
font-size:12pt
}
""")
sys.exit(app.exec_())
def GetBestMatch():
print ("HI")
if __name__ == '__main__':
MainWindow()
レイアウトは間違いなく完璧に機能します。これで私を助けてくれますか?
これはwoooorks!ありがとうセバスチャン!あなたは素晴らしい一日を期待しています:) – Sarah
あなたは歓迎です:)私の答えを受け入れてください、それは助けられました;) – sebastian
あなたはそれをupvote意味ですか?悲しいことに、私は新しいユーザーであるので、私はアップヴォートに "許可"されていません:( – Sarah