Answer the question
In order to leave comments, you need to log in
How to access an interface from another module?
Good afternoon.
Tell me, please, is it possible to access the program interface from another module, that is, like this:
main.py:
from PyQt5 import QtWidgets, QtGui, uic
import sys
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
def load_main_window(self):
uic.loadUi('resources/main.ui', self)
self.setWindowTitle('Program')
self.show()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
main_window = MainWindow()
main_window.load_main_window()
sys.exit(app.exec_())
from main import MainWindow
a = MainWindow()
a.label.setText('Test')
Answer the question
In order to leave comments, you need to log in
It ends just the same with an error and a very serious one - you made a recursive call and the application crashed when it reached the recursion limit.
If you want to access an object from different modules, then either initialize it in a third module and import it, or pass it as an object reference.
This is so, offhand, without understanding why you need to do it this way.
In general, it makes sense for you to read about how to correctly untie components in an application.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question