我想在PySide中做一個簡單的測試應用程序,我真的不理解我錯過了什麼。這是目前爲止的代碼:PySide,連接PushButton錯誤
import sys
from PySide import QtCore, QtGui
class IPTest(QtGui.QMainWindow):
def __init__(self):
super(BartonTest, self).__init__()
self.initUI()
def initUI(self):
lblAddress = QtGui.QLabel("IP Address", self)
lineAddress = QtGui.QLineEdit(self)
lblPort = QtGui.QLabel("Port Number", self)
linePort = QtGui.QLineEdit(self)
btnSend = QtGui.QPushButton("Send", self)
btnReceive = QtGui.QPushButton("Receive", self)
lblAddress.move(30, 20)
lblPort.move(30, 60)
lineAddress.move(130, 20)
linePort.move(130, 60)
btnSend.move(30, 100)
btnReceive.move(130, 100)
self.setGeometry(200, 200, 275, 150)
self.setWindowTitle('Send/Receive TCP Test Program')
self.show()
def sendData(self):
fileName, _ = QtGui.QFileDialog.getOPenFileName(self, 'Open CNC Program')
self.data = open(fileName, 'r')
def main():
app = QtGui.QApplication(sys.argv)
bt = IPTest()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
現在我想要做的只是將一個事件連接到按鈕。 Qt的文檔告訴我,我需要做的是:
btnSend.clicked.connect(self.sendData)
PyCharm說,它無法找到參考點擊和我得到的例外是
TypeError: native Qt signal is not callable
我非常(很容易)難住了。
看起來正確的。你能準確地發佈你正在做的事情嗎? – tacaswell 2013-02-14 01:42:23
我想你忘了'.connect'部分並且做了'btnSend.clicked(self.sendData)'。這會給你帶來的錯誤。 – Avaris 2013-02-14 11:42:16