我得到python代码的AttributeError

时间:2014-01-06 07:45:56

标签: python-3.x

我是python的新手,请帮助我解决这个问题我创建了一个标签小部件并在标签小部件中有按钮,单击该按钮我需要显示一个包含4到5行编辑的新窗口/对话框但我是在按钮单击调用方法时获取属性错误请帮我解决这个问题 这是我的代码

 class TabDialog(QtGui.QDialog):

    def __init__(self, fileName, parent=None):
    super(TabDialog, self).__init__(parent)

    fileInfo = QtCore.QFileInfo(fileName)

    tabWidget = QtGui.QTabWidget()
    tabWidget.addTab(PatientTab(fileInfo), "Patient Info")
     ....
class NewWindow(QtGui.QDialog):
def __init__(self, parent=None):
        super(MyWindow, self).__init__(parent)

    group1= QtGui.QGroupBox("Add Data")
    patientName = QtGui.QLabel("Name")
    patientEdit = QtGui.QLineEdit()

    patientid = QtGui.QLabel("Id")
    patientidEdit = QtGui.QLineEdit()

    genderlabel = QtGui.QLabel("Gender")
    patientgend = QtGui.QLineEdit()

    eyeType = QtGui.QLabel("Eye Type")
    eyeTypeEdit = QtGui.QLineEdit()

    AddData = QtGui.QPushButton("Add Data")

            databaseLayout = QTGui.QGridLayout()
    databaseLayout.addWidget(patientName,0,0)
        databaseLayout.addWidget(patientEdit,0,1)
        databaseLayout.addWidget(patientid,1,0)
        databaseLayout.addWidget(patientidEdit,1,1)
        databaseLayout.addWidget(genderLabel,2,0)
        databaseLayout.addWidget(patientgend,2,1)
        databaseLayout.addWidget(eyeType,3,0)
        databaseLayout.addWidget(eyeTypeEdit,3,1)
        databaseLayout.addWidget(AddData,4,10)

        group1.setLayout(databaseLayout)

    mainLayout = QtGui.QVBoxLayout()
    mainLayout.addWidget(group1)
    mainLayout.addStretch(1)
    self.setLayout(mainLayout)

class PatientTab(QtGui.QWidget):

  def __init__(self, fileInfo, parent=None):
    super(PatientTab, self).__init__(parent)

    self.buttonGroup = QtGui.QGroupBox()
    self.newButton = QtGui.QPushButton(self)
self.newButton.setText("New")
    ***self.newButton.clicked.connect(self.newButton_Clicked)
    .........
    self.newWindow = NewWindow(self)


def newButton_Clicked(self):
    self.newWindow.exec_()

* 开头的行是我收到错误的地方 AttributeError:'PatientTab'对象没有属性'newButton_Clicked' 哪里出错我请帮忙......

1 个答案:

答案 0 :(得分:1)

问题中的缩进是否与代码中的缩进相同?

看来你的newButton_Clicked方法是在PatientTab类的范围之外声明的。这就是为什么你的PatientTab注意到有一个self.newButton_Clicked属性......