So I have created a stacked widget with 2 pages. In the first page, I have one button \" Sign In \". In the second page, I have One button \" Logout\"
I want that, if I
According to the code you provide, I deduce that you used StackedWidget as a template, so the class you use fills in ui to inherit from that class.
An error that I see in your code is self.ui.StackedWidget
since ui has no attribute called StackedWidget
, so you should throw an exception.
Considering the above, the solution is:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_StackedWidget(object):
def setupUi(self, StackedWidget):
# ...
def retranslateUi(self, StackedWidget):
# ...
class StackedWidget(QtWidgets.QStackedWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_StackedWidget()
self.ui.setupUi(self)
self.ui.LogoutBtn.clicked.connect(lambda : self.setCurrentIndex(0))
self.ui.pushButton.clicked.connect(lambda : self.setCurrentIndex(1))
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = StackedWidget()
w.show()
sys.exit(app.exec_())