Answer the question
In order to leave comments, you need to log in
How to link .py files together?
There are 4 files: AuthorForm.py, ProjectForm.py, PassOptionsForm.py and OptionsForm.py.
AuthorForm.py has a button that opens ProjectForm.py, and it has a button to open PassOptionsForm.py, and so on. But it turns out that if you run AuthorForm.py, then the button opens ProjectForm.py, and its button no longer works to open PassOptionsForm.
If you run the files separately, that is, for example, ProjectForm.py and click on the button, then PassOptionsForm.py will open and so on with each file.
How to link files together so that when I open AuthorForm.py, I can open the OptionsForm.py window using buttons from other files (windows).
The code is almost identical in all files.
AuthorForm.py code:
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMessageBox
from ProjectUIForm import Ui_Form as Ui_F_Project
class Ui_Form(object):
def setupUi(self, Form):
...
def retranslateUi(self, Form):
...
class ProjectPrg(QtWidgets.QWidget, Ui_F_Project):
def __init__(self, parent=None):
super(ProjectPrg, self).__init__(parent)
self.setupUi(self)
class Main(QtWidgets.QWidget, Ui_Form):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.setupUi(self)
self.auth_btn.clicked.connect(self.OpenProject)
def OpenProject(self):
l = "admin"
p = "password"
msg = QMessageBox(self)
if self.lineLOGIN.text() == l and self.linePASS.text() == p:
self.FProj = ProjectPrg()
self.FProj.show()
elif self.lineLOGIN.text() == "" and self.linePASS.text() == "":
msg.about(self, "Ошибка", "Введите логин и пароль.")
else:
msg.about(self, "Ошибка", "Вы ввели неверный логин или пароль.")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Main()
w.show()
sys.exit(app.exec_())
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
from PassOptionsForm import Ui_Form as Ui_F_PassOpt
class Ui_Form(object):
def setupUi(self, Form):
...
def retranslateUi(self, Form):
...
class PassOptionsPrg(QtWidgets.QWidget, Ui_F_PassOpt):
def __init__(self, parent=None):
super(PassOptionsPrg, self).__init__(parent)
self.setupUi(self)
class Main(QtWidgets.QWidget, Ui_Form):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.setupUi(self)
self.btnOpenOpt.clicked.connect(self.onClicked)
def onClicked(self):
self.FPassOpt = PassOptionsPrg()
self.FPassOpt.show()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Main()
w.show()
sys.exit(app.exec_())
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMessageBox
from OptionsForm import Ui_Form as Ui_F_Options
class Ui_Form(object):
def setupUi(self, Form):
...
def retranslateUi(self, Form):
...
class OptionsPrg(QtWidgets.QWidget, Ui_F_Options):
def __init__(self, parent=None):
super(OptionsPrg, self).__init__(parent)
self.setupUi(self)
class Main(QtWidgets.QWidget, Ui_Form):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.setupUi(self)
self.openopt.clicked.connect(self.onClicked1)
def onClicked1(self):
l = "admin"
p = "password"
msg = QMessageBox(self)
if self.lineLOGINopt.text() == l and self.linePASSopt.text() == p:
self.FOpenOpt = OptionsPrg()
self.FOpenOpt.show()
elif self.lineLOGINopt.text() == "" and self.linePASSopt.text() == "":
msg.about(self, "Ошибка", "Введите логин и пароль.")
else:
msg.about(self, "Ошибка", "Вы ввели неверный логин или пароль.")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Main()
w.show()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question