I have a repeat
python function and a test.ui which has only one push-button. My doubt is how to loop the same function exactly once for every time the button is clicked. Because for me whenever I perform:
self.pushButton.clicked.connect(self.repeat)
it loops many times into the function instead of a single time. I found this by incrementing a value for every time we reach the function. How to reach the function repeat
exactly once for every click on the push-button?
import sys
from PyQt4 import QtCore, QtGui, uic
qtCreatorFile = "test.ui"
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class Login(QtGui.QMainWindow, Ui_MainWindow):
i=1
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.pushButton.setText("iam in init")
self.pushButton.clicked.connect(self.repeat)
def repeat(self):
self.pushButton.setText("iam in repeat"+str(self.i))
self.i=self.i+1
self.pushButton.clicked.connect(self.repeat)
if __name__ == "__main__":
app=QtGui.QApplication(sys.argv)
main = Login()
main.show()
sys.exit(app.exec_())