我试图将按钮信号连接到我创建的可调用信号,但由于某种原因,此错误不断弹出.我已经检查过确保导入了QtCore ...我还缺少什么?
示例代码:
from PyQt4 import QtCore
from PyQt4 import QtGui
import sys
class guiFindFiles(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
#Create window
self.setFixedSize(400,180)
self.setWindowTitle("Choose the files to use")
#Create all layouts to be used by window
self.windowLayout = QtGui.QVBoxLayout()
self.fileLayout1 = QtGui.QHBoxLayout()
self.fileLayout2 = QtGui.QHBoxLayout()
self.fileLayout3 = QtGui.QHBoxLayout()
#Create the prompt for user to load in the q script to use
self.qFileTF = QtGui.QLineEdit("Choose the q script file to use")
self.qFileButton = QtGui.QPushButton("Open")
self.qFileButton.setFixedSize(100,27)
self.fileLayout1.addWidget(self.qFileTF)
self.fileLayout1.addWidget(self.qFileButton)
#Connect all the signals and slots
self.connect(self.qFileButton, SIGNAL("pressed()"), self.loadFile)
def loadFile():
fileName = []
selFile = QtGui.QFileDailog.getOpenFileName(self)
print selFile
Run Code Online (Sandbox Code Playgroud)
SIGNAL在里面QtCore,所以该行应该是:
self.connect(self.qFileButton, QtCore.SIGNAL("pressed()"), self.loadFile)
Run Code Online (Sandbox Code Playgroud)
但你真的应该使用新的风格连接:
self.qFileButton.pressed.connect(self.loadFile)
Run Code Online (Sandbox Code Playgroud)
而且,除非你的意思是区分click由press/release夫妇,你最好使用clicked信号:
self.qFileButton.clicked.connect(self.loadFile)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7163 次 |
| 最近记录: |