Answer the question
In order to leave comments, you need to log in
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_())
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question