This question already has an answer here:
- How do I switch layouts in a window using PyQt?? (Without closing/opening windows) 1 answer
I've built an application to perform different analyses in a single platform with using tkinter but now I'm trying to convert it to PyQT to improve visualisation for a presentation. My app consists of two different frames that are reachable from the buttons of my main frame.
In tkinter I created a Controller class for switching frames but I'm really new on PyQt and I could not achieve it or any reasonable error code. I simplified my code below.
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class MainWindow(object):
def setupUi(self, MainFrame):
MainFrame.setObjectName("MainFrame")
MainFrame.resize(870, 230)
MainFrame.setFrameShape(QFrame.Box)
self.Function1Button = QPushButton(MainFrame)
#I want to go Function 1's frame with this button
self.Function1Button.clicked.connect(????)
self.Function2Button = QPushButton(MainFrame)
#I want to go Function 2's frame with this button
self.Function2Button.clicked.connect(????)
class Function1(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(870, 230)
self.BackButton = QPushButton(MainFrame)
# I want to go previous frame with this button
self.BackButton.clicked.connect(????)
self.Function2Button = QPushButton(MainFrame)
#I want to go Function 2's frame with this button
self.Function2Button.clicked.connect(????)
self.ExecuteButton = QPushButton(MainFrame)
self.ExecuteButton.clicked.connect(self.runfunc)
def runfunc(self):
# Computations
class Function2(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(870, 230)
self.BackButton = QPushButton(MainFrame)
self.BackButton.clicked.connect(????)
self.Function1Button = QPushButton(MainFrame)
#I want to go Function 1's frame with this button
self.Function1Button.clicked.connect(????)
self.ExecuteButton = QPushButton(MainFrame)
self.ExecuteButton.clicked.connect(self.runfunc)
def runfunc(self):
# Computations
I want to open my mainwindow on start, then with the buttons on my mainwindow, I want to open functions' frames. With the back buttons inside of the function frames I want to return previous frame. And also I want to reach Function 2's frame from Function 1 with Function1Button or vice versa.