I understand what you're saying but at the same time confused. I thought if a class or function inherited another class then the child class can access any of the objects within the parent class? I thought inheritance was pretty much extending the parent class.
The code you wrote with the lambda function confuses me. To me it seems you're just creating another separate instance of the text boxes? Obviously it works since I see the output and tested the print function in my code and it printed. I just don't understand the code. I tried using the lambda function in my code but the app just closes when clicking the button and no data is entered. Although if I just print the text boxes it does work. But I need that data to be entered into my database. It's hard to debug when the app isn't throwing any error codes.
The code you wrote with the lambda function confuses me. To me it seems you're just creating another separate instance of the text boxes? Obviously it works since I see the output and tested the print function in my code and it printed. I just don't understand the code. I tried using the lambda function in my code but the app just closes when clicking the button and no data is entered. Although if I just print the text boxes it does work. But I need that data to be entered into my database. It's hard to debug when the app isn't throwing any error codes.
from PyQt5.QtWidgets import (QLabel, QPushButton, QLineEdit, QApplication, QCheckBox, QMainWindow, QWidget, QVBoxLayout, QTabWidget, QStatusBar) import pyodbc import sys class mainWindow(QMainWindow): def __init__(self): super().__init__() self.resize(385, 323) self.setWindowTitle("HARDWARE | SOFTWARE MANAGER") self.statusBar = QStatusBar() self.setStatusBar(self.statusBar) self.tabForm = QTabWidget() self.tabForm.addTab(hardwareTab(), "HARDWARE") self.tabForm.addTab(softwareTab(), "SOFTWARE") self.setCentralWidget(self.tabForm) class hardwareTab(QWidget): def __init__(self): super().__init__() self.snLabel = QLabel("SERIAL NUMBER") self.snTextBox = QLineEdit() self.modelLabel = QLabel("MODEL") self.modelTextBox = QLineEdit() self.userLabel = QLabel("USER") self.userTextBox = QLineEdit() self.enButton = QPushButton("ENTER NEW HARDWARE") self.cfButton = QPushButton("CLEAR FIELDS") self.seButton = QPushButton("SEARCH/EDIT HARDWARE") self.activeCheckbox = QCheckBox("ACTIVE") self.testTextbox = QLineEdit() layout = QVBoxLayout(self) layout.addWidget(self.snLabel) layout.addWidget(self.snTextBox) layout.addWidget(self.modelLabel) layout.addWidget(self.modelTextBox) layout.addWidget(self.userLabel) layout.addWidget(self.userTextBox) layout.addWidget(self.activeCheckbox) layout.addWidget(self.enButton) layout.addWidget(self.cfButton) layout.addWidget(self.seButton) layout.addWidget(self.testTextbox) self.enButton.clicked.connect(lambda: enterNewHardware(self)) def enterNewHardware(tab): serial_number = tab.snTextBox.text() model_name = tab.modelTextBox.text() user_name = tab.userTextBox.text() test_textbox = tab.testTextbox.text() azureServer = "pythonserver5874.database.windows.net" azureDB = "inventoryDatabase" userName = "na" password = "na" driver = "{ODBC Driver 17 for SQL Server}" connectionString = f"DRIVER={driver};SERVER={azureServer};PORT=1433;DATABASE={azureDB};UID={userName};PWD={password}" conn = pyodbc.connect(connectionString) cursor = conn.cursor() sql_statement = 'INSERT INTO inventoryDatabase.dbo.Hardware(serialNumber, modelName, userName, machineActive) VALUES (?, ?, ?, ?)' data = (serial_number, model_name, user_name, test_textbox) cursor.execute(sql_statement, data) conn.commit() class softwareTab(QWidget): def __init__(self): super().__init__() self.snLabel = QLabel("SERIAL NUMBER / KEY") self.snTextbox = QLineEdit() self.nameLabel = QLabel("APPLICATION NAME") self.nameTextBox = QLineEdit() self.userLabel = QLabel("USER") self.userTextBox = QLineEdit() self.enButton = QPushButton("ENTER NEW SOFTWARE") self.cfButton = QPushButton("CLEAR FIELDS") self.seButton = QPushButton("SEARCH/EDIT SOFTWARE") layout = QVBoxLayout(self) layout.addWidget(self.snLabel) layout.addWidget(self.snTextbox) layout.addWidget(self.nameLabel) layout.addWidget(self.nameTextBox) layout.addWidget(self.userLabel) layout.addWidget(self.userTextBox) layout.addWidget(self.enButton) layout.addWidget(self.cfButton) layout.addWidget(self.seButton) if __name__ == "__main__": APP = QApplication(sys.argv) WINDOW = mainWindow() WINDOW.show() sys.exit(APP.exec_())I don't see how I'm referencing the original text boxes from the hardwareTab class here:
def enterNewHardware(tab): serial_number = tab.snTextBox.text() model_name = tab.modelTextBox.text() user_name = tab.userTextBox.text() test_textbox = tab.testTextbox.text()I understand what I need to do in my head I think it's the coding that is throwing me for a loop.