Okay, I am jumping from Tkinter to PyQt, because PyQt is just so much more advanced, and nicer to work with. BUT! I am having some troubles here.
I am trying to change the GUI layout after I press one of my buttons on the main screen. I press the first button of the main GUI page, then I want it to go to another GUI page that I will create. I have been sitting here for hours trying to find some way to do this - no videos on YouTube, and I haven't found any stack-overflow pages that help. So I learnt that there is a Qt Designer program. I don't like programs like that, so please try to stay away from using that when answering.
PS: I don't want to be working with more than one .py file, but if there is no other way, I guess I'm going to have to do so.
Here is my code so far:
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(50, 50, 400, 450)
self.setFixedSize(400,450)
self.setWindowTitle(" Tool")
self.setWindowIcon(QtGui.QIcon('PhotoIcon.png'))
self.home()
def home(self):
ToolsBTN = QtGui.QPushButton('text', self)
ToolsBTN.clicked.connect(ToolTab)
ToolsBTN.move(50, 350)
CPSBTN = QtGui.QPushButton('text', self)
CPSBTN.clicked.connect(QtCore.QCoreApplication.instance().quit)
CPSBTN.move(150, 350)
CreatorBTN = QtGui.QPushButton('Creator', self)
CreatorBTN.clicked.connect(QtCore.QCoreApplication.instance().quit)
CreatorBTN.move(250, 350)
self.show()
class ToolTab(QtGui.QMainWindow):
def __init__2(self):
super(ToolTab, self).__init__2()
self.setGeometry(50, 50, 400, 450)
self.setFixedSize(400,450)
self.setWindowTitle(" Tool")
self.setWindowIcon(QtGui.QIcon('PhotoIcon.png'))
self.Toolsgui()
def Toolsgui(self):
CPSBTN = QtGui.QPushButton('123', self)
CPSBTN.clicked.connect(QtCore.QCoreApplication.instance().quit)
CPSBTN.move(150, 300)
self.show()
def Run():
app = QtGui.QApplication(sys.argv)
GUI = Window()
GUITOOL = ToolTab()
sys.exit(app.exec_())
Run()
The solution I propose is based on the function
setupUi()
that generates Qt Designer, this is responsible for creating the internal elements of the window.Start:
After button clicked:
After another button clicked:
and more elegant solution: