Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pyqt5 connecting button press to a stackedWidget

I just converted my .ui file into the py file and tried to link a QPushButton to a QStackedWidget using the signals and slots system. This is what I attempted to do:

self.createButton.clicked.connect(self.stackedWidget.setCurrentIndex(2)) 

and it was supposed to set the index of the stacked widget to 2 on button click. However at runtime the following error occurred:

TypeError: argument 1 has unexpected type 'NoneType'

Was not really sure what argument 1 was, but the placeholder code of:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

self.createButton.clicked.connect(self.stackedWidget.update)

seemed to work except that was not what I want to achieve. What is wrong with my code?

>Solution :

the the connect function takes as a parameter a function to call when the click event is emited so you should wrap your statment in a lambda function as follows :

self.createButton.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(2)) 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading