F
F
ForeverNoob2016-08-27 17:16:20
Python
ForeverNoob, 2016-08-27 17:16:20

I tried to create a slot in PyQt4, but, for some reason, the IDE gives an error. How to create my own slot?

import sys
from PyQt4 import QtGui, QtCore

class SigSlot(QtGui.QWidget):
  def __init__(self, parent=None):
    QtGui.QWidget.__init__(self, parent)
      
    self.setWindowTitle('signal & slot')
    but=QtGui.QPushButton('КНОПКА',self)
    but.resize(200, 100)
    but.clicked.connect(self.function)
    def Scr(self):
      print('test')
    self.resize(250, 150)
app = QtGui.QApplication(sys.argv)
qb = SigSlot()
qb.show()
sys.exit(app.exec_())

Error:
Traceback (most recent call last):
File "111.py", line 16, in
qb = SigSlot()
File "111.py", line 11, in __init__
but.clicked.connect(self.function)
AttributeError: 'SigSlot' object has no attribute 'function'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Romanov, 2016-08-27
@Djaler

Your SigSlot class does not have a function method

F
ForeverNoob, 2016-08-29
@ForeverNoob

I found the problem is indentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question