How to change formularies in different modules

Asked

Viewed 53 times

0

I’m using Python 3.7

I have 2 forms (windows) that I made with Pyqt5, in one of them have some Labels that I need to change according to the settings window configuration.

created a modules with the following function:

def calculaTaxas(self):
    valorBase = self.ui.lbl_saldoAtual.text()

When I call the function from the main window, the data loads normally.

But when I change the data and try to call the function by the settings window to update the main screen with the new values, the following error appears:

AttributeError: 'Ui_frm_Config' object has no attribute 'lbl_saldoAtual'

I understood that he is passing the form of config to the self of the function, I tried in several ways update the screen and could not, not even trying to call directly:

valorBase = Ui_frm_principal.lbl_saldoAtual.text()

What I would really like is to be able to call the function calculaTaxas() without SELF as parameter so I can update the main screen of any part of the code or window.

I don’t know if it’s relevant, but follow the screen configuration.

Main Screen:

class TelaPrincipal(QMainWindow):  
    def __init__(self,*args,**argsv):        
        super(TelaPrincipal,self).__init__(*args,**argsv)
        self.ui = Ui_frm_principal()
        self.ui.setupUi(self)

Configuration screen:

class TelaConfig(QMainWindow):     
    def __init__(self,*args,**argsv):
        super(TelaConfig,self).__init__(*args,**argsv)
        self.ui = Ui_frm_Config()
        self.ui.setupUi(self)

1 answer

1


Hello, I use a controller to call functions and variables from the main screen, maybe this will help you:

import sys
from PyQt5.QtWidgets import *


class TelaPrincipal(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(TelaPrincipal, self).__init__(*args, **kwargs)
        # self.ui = Ui_frm_principal()
        # self.ui.setupUi(self)
        self.setWindowTitle('Tela Principal')
        self.setGeometry(100, 200, 300, 200)

        self.tela_config = TelaConfig(self)

        self.saldo_actual = QLabel(self)
        self.saldo_actual.move(100, 100)

    def calculaTaxas(self):
        valorBase = self.tela_config.saldo.value()
        self.saldo_actual.setText(str(valorBase))


class TelaConfig(QWidget):
    def __init__(self, controller):
        super(QWidget, self).__init__()
        # self.ui = Ui_frm_Config()
        # self.ui.setupUi(self)
        self.controller = controller

        self.setWindowTitle('Tela Config')
        self.setGeometry(500, 200, 300, 200)

        self.layout = QVBoxLayout(self)

        self.saldo = QSpinBox(self)
        self.saldo.move(100, 100)
        self.saldo.valueChanged.connect(self.controller.calculaTaxas)

        self.layout.addWidget(self.saldo)

        self.setLayout(self.layout)
        self.show()


def main():
    app = QApplication(sys.argv)
    root = TelaPrincipal()
    root.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.