Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Pyqt: AttributeError: 'Object' has not attribute 'someFunction'

Pyqt: AttributeError: 'Object' has not attribute 'someFunction'

Scheduled Pinned Locked Moved Language Bindings
2 Posts 2 Posters 4.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    s03r3n
    wrote on 2 Dec 2014, 15:46 last edited by
    #1

    Hey there.

    I am trying to run this example:
    @import sys
    from PyQt4 import QtGui, QtCore

    class Window(QtGui.QWidget):

    def __init__(self):
        super(Window, self).__init__()       
        self.initUI()
    
    def initUI(self):
        self.setWindowTitle('Who is online?')
        self.setGeometry(50, 50, 730, 326)
    
        self.labelF = QtGui.QLabel(self)
        self.labelF.setGeometry(QtCore.QRect(395, 50, 111, 31))
        self.labelF.setFrameShape(QtGui.QFrame.StyledPanel)
        self.labelF.setAlignment(QtCore.Qt.AlignCenter)
        self.labelF.setText('')
    
        self.pushButton = QtGui.QPushButton("Quit", self)
        self.pushButton.setGeometry(QtCore.QRect(620, 290, 101, 27))
        self.pushButton.clicked.connect(QtCore.QCoreApplication.instance().quit)
    
        self.buttonA = QtGui.QPushButton("A", self)
        self.buttonA.setGeometry(QtCore.QRect(110, 290, 101, 27))
        self.buttonA.clicked.connect(self.setA)
    
        self.show()
    

    def setA(self):
    self.labelF.setText('InstructorA')

    def setD(self):
    self.labelF.setText('InstructorB')

    def main():
    app = QtGui.QApplication(sys.argv)
    ex = Window()
    sys.exit(app.exec_())

    if name == 'main':
    main()
    @

    The button 'buttonA' is causing an error with the function 'setA'. The error message says:
    Attribute Error "'Window' has no attribute 'setA'"

    I compared my code to other examples that use a button and can't figure out how my code differs from those examples... Any help would be appreciated. Thanks in advance!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Dec 2014, 21:36 last edited by
      #2

      Hi and welcome to devnet,

      Might be a silly question but did you indent your source correctly ? The code you posted shows that setA is not part of Window since it's at the same level as e.g. main

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      2/2

      2 Dec 2014, 21:36

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved