Unsolved Pyside2: How can load new window inside Main Window?
-
-
@Marcone
Depends whatmain.py
& new.py` have in them, what widgets they define and how, etc.It is often the case with this kind of question that you should consider using a
QStackedWidget
. But as I say, depends what you have. -
@JonB said in Pyside2: How can load new window inside Main Window?:
main.py & new.py`
main.py and new.py are independent MainWindows form. Not QStackedWidget case.
-
-
@JonB I want create every window in separated .ui forms and call everyone when needed. How can I make it? can you send simple example?
-
@Marcone
You can paste your code if you wish, not send me something. I am not going to send you anything.I have no idea what you mean by having separated forms, and each of type
QMainWindow
, but displaying each one without it being a new window. Showing code won't explain that to me.Since you won't consider
QStackedWidget
, at the end of the day you will presumably want pushbutton code which justshow()
s the other window andhide()
s the current window, and that's all there is to say. -
My code: This file is called Program.py and import two files: untitled.py (Main) and newform.py (New window to load)
# -*- coding: utf-8 -*- import sys from PySide2 import QtCore, QtGui, QtWidgets from untitled import Ui_MainWindow from newform import Ui_Form class Form2(QtWidgets.QMainWindow, Ui_Form): def __init__(self): super(Form2, self).__init__() self.setupUi(self) self.bt2.clicked.connect(self.fun) def fun(self): print('Go to form 1') class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): def __init__(self): super(MainWindow, self).__init__() self.setupUi(self) self.bt1.clicked.connect(self.fun) def fun(self): print('Go to form 2') if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())