Unsolved Calling a lineEdit value from one form to another form
I want to call the LineEdit value (id_no) from form A on form B and C. Each form has a unique content and a unique database table. Any assistance please?Thanks in advance.
class MainWindow(QtWidgets.QMainWindow): def __init__(self, mainMenu): global new_id_no new_Id_no= id_no super(MainWindow, self).__init__() self.mainMenu = mainMenu self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.First_Add_Button.clicked.connect(self.Form_A) self.ui.Second_Add_Button.clicked.connect(self.Form_B) self.ui.Third_Add_Button.clicked.connect(self.Form_C) def Form_A(self): id_no = self.ui.lineEdit.text() name = self.ui.lineEdit_1.text() def Form_B(self): address = self.ui.lineEdit_2.text() city = self.ui.lineEdit_3.text() def Form_C(self): country = self.ui.lineEdit_4.text()
JonB last edited by JonB
call the LineEdit value (id_no)
Don't know what "calling" a line edit or its value means. Your "Form"s are just methods in class
MainWindow, no other classes here. Your variables inside the methods (
address, etc.) are just local variables in the methods, so they are irrelevant for the outside world. There is nothing here to use other than the necessary
self.ui.lineEdit_someNumberfrom no matter which method. Unless you want to do something about rewriting your code, like utility getters (or you could use a Python
@propertydecorator if you prefer):
def address(): return self.ui.lineEdit_2.text()
def Form_A(self): self.id_no = self.ui.lineEdit.text()
but that is not clever coding practice.
The logic of whatever you intend by calling
First_Add_Button.clickedis not clear, as it stands it accomplishes nothing.
@JonB Thanks for your response . I want to pass the id_no to the other forms database. I declared it as a global variable and it worked.
JonB last edited by
I declared it as a global variable and it worked.
I know, but that is so not the way to do it!
I don't begin to have the time to show & teach you what you should be doing, I'm afraid....