I
I
Issue2019-07-05 00:56:00
linux
Issue, 2019-07-05 00:56:00

How to open a window on QPushButton click in PyQT5?

In the process of studying PyQT5, a lot of questions arose for which I can not find a clear answer.
I created the main form of the program in QT Designer, saved it as main.ui > ran through pyuic5 > got ui.py.
I created a second file so that when editing the ui form , my code would not fly into ui.py, so to launch the main form and work with it, I made the second main.py file:

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from os import system as go
from os import getcwd as mainpath
from ui import Ui_MainWindow //здесь импотированна форма ui.py полученная через PyUIC5

app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()

main_path =   "'{}'".format(str(mainpath())) # здесь я получаю путь к текущему файлу(запущеному)
path = "cd " + main_path + "/ui/  " # переход к папке /ui

def formstart():
  go( path + "&& python3 add-account.py") # Запуск /ui/add-account.py через os.system

ui.pushButton.clicked.connect( formstart ) # при нажатии кнопки запускается другая форма

sys.exit(app.exec_())

This method does not suit me at all, with this method the main form completely stops responding until I close the running form.
Can you please tell me how it would be more correct to open additional forms in PyQt5?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Issue, 2020-03-28
@paulenot

def start_window():
    from ui import Ui_MainWindow //здесь импотированна форма ui.py полученная через PyUIC5
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
  
ui.pushButton.clicked.connect(start_window)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question