Как добавить чтобы вводные данные в окно регистрация ещё сохранялись водные данные в ячейку Электронная почта в файл user_data.txt
from PyQt6.QtCore import pyqtSlot
from PyQt6.QtWidgets import QApplication, QMainWindow, QMessageBox
import sys
import os
from Authorization import Ui_Authorization
from Registration import Ui_Registration

DATA_FILE = "user_data.txt"

class AuthorizationWindow(QMainWindow, Ui_Authorization):
    def __init__(self):
        super(AuthorizationWindow, self).__init__()
        self.setupUi(self)
        
        # Handle "Зарегистрироваться"button click
        self.pushButton_3.clicked.connect(self.open_registration)

        # Handle "Войти"button click
        self.pushButton.clicked.connect(self.login)

        self.user_data = self.load_user_data()

    def load_user_data(self):
        """Load user data from a file."""
        if not os.path.exists(DATA_FILE):
            return {}
        
        user_data = {}
        with open(DATA_FILE, "r") as file:
            for line in file:
                username, password = line.strip().split(",")
                user_data[username] = password
        return user_data

    def save_user_data(self):
        """Save user data to a file."""
        with open(DATA_FILE, "w") as file:
            for username, password in self.user_data.items():
                file.write(f"{username},{password}\n")
    
    @pyqtSlot()
    def open_registration(self):
        self.registration_window = RegistrationWindow(self)
        self.registration_window.show()

    @pyqtSlot()
    def login(self):
        username = self.lineEdit.text()
        password = self.lineEdit_2.text()

        msg_box = QMessageBox(self)
        msg_box.setStyleSheet("background-color: white;")

        if username in self.user_data and self.user_data[username] == password:
            msg_box.setText("Вы успешно вошли в систему!")
            msg_box.setIcon(QMessageBox.Icon.Information)
        else:
            msg_box.setText("Неверный логин или пароль!")
            msg_box.setIcon(QMessageBox.Icon.Warning)
            
        msg_box.exec()


class RegistrationWindow(QMainWindow, Ui_Registration):
    def __init__(self, auth_window):
        super(RegistrationWindow, self).__init__()
        self.setupUi(self)

        # Reference to the authorization window to store user data
        self.auth_window = auth_window

        # Handle "Сохранить"button click
        self.pushButton.clicked.connect(self.save_registration)

    @pyqtSlot()
    def save_registration(self):
        email = self.lineEdit_3.text()
        username = self.lineEdit.text()
        password = self.lineEdit_2.text()
        confirm_password = self.lineEdit_4.text()

        msg_box = QMessageBox(self)
        msg_box.setStyleSheet("background-color: white;")

        if password != confirm_password:
            msg_box.setText("Пароли не совпадают!")
            msg_box.setIcon(QMessageBox.Icon.Warning)
            msg_box.exec()
            return

        self.auth_window.user_data[username] = password
        self.auth_window.save_user_data()
        msg_box.setText("Регистрация успешна!")
        msg_box.setIcon(QMessageBox.Icon.Information)
        msg_box.exec()

        self.close()


def main():
    app = QApplication(sys.argv)

    auth_window = AuthorizationWindow()
    auth_window.show()

    sys.exit(app.exec())


if __name__ == "__main__":
    main()
# Form implementation generated from reading ui file 'Authorization.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_Authorization(object):
    def setupUi(self, Authorization):
        Authorization.setObjectName("Authorization")
        Authorization.resize(705, 557)
        Authorization.setStyleSheet("background-color: rgb(0, 196, 255);")
        self.centralwidget = QtWidgets.QWidget(parent=Authorization)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.widget = QtWidgets.QWidget(parent=self.centralwidget)
        self.widget.setMinimumSize(QtCore.QSize(400, 400))
        self.widget.setMaximumSize(QtCore.QSize(400, 400))
        self.widget.setStyleSheet("QWidget {\n"
"    background-color: rgb(255, 255, 255);\n"
"    border-radius: 15px;\n"
"}\n"
"")
        self.widget.setObjectName("widget")
        self.widget1 = QtWidgets.QWidget(parent=self.widget)
        self.widget1.setGeometry(QtCore.QRect(60, 40, 281, 311))
        self.widget1.setObjectName("widget1")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.widget1)
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.label = QtWidgets.QLabel(parent=self.widget1)
        self.label.setMinimumSize(QtCore.QSize(50, 49))
        self.label.setMaximumSize(QtCore.QSize(16777215, 50))
        font = QtGui.QFont()
        font.setPointSize(16)
        font.setBold(True)
        font.setItalic(False)
        font.setUnderline(False)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setLayoutDirection(QtCore.Qt.LayoutDirection.LeftToRight)
        self.label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout_2.addWidget(self.label)
        self.lineEdit = QtWidgets.QLineEdit(parent=self.widget1)
        self.lineEdit.setStyleSheet("QLineEdit {\n"
"    border: 2px solid darkgray;\n"
"    border-radius: 15px;\n"
"    padding: 0 8px;\n"
"    background: white;\n"
"    selection-background-color: lightblue;\n"
"    width: 30px;\n"
"    height: 30px;\n"
"}\n"
"\n"
"QLineEdit:focus {\n"
"    border: 2px solid gray; /* Цвет границы станет темнее при фокусе */\n"
"}")
        self.lineEdit.setObjectName("lineEdit")
        self.verticalLayout_2.addWidget(self.lineEdit)
        self.lineEdit_2 = QtWidgets.QLineEdit(parent=self.widget1)
        self.lineEdit_2.setStyleSheet("QLineEdit {\n"
"    border: 2px solid darkgray;\n"
"    border-radius: 15px;\n"
"    padding: 0 8px;\n"
"    background: white;\n"
"    selection-background-color: lightblue;\n"
"    width: 30px;\n"
"    height: 30px;\n"
"}\n"
"\n"
"QLineEdit:focus {\n"
"    border: 2px solid gray; /* Цвет границы станет темнее при фокусе */\n"
"}")
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.verticalLayout_2.addWidget(self.lineEdit_2)
        self.checkBox = QtWidgets.QCheckBox(parent=self.widget1)
        self.checkBox.setStyleSheet("QCheckBox {\n"
"    spacing: 5px; /* Отступ между квадратом и текстом */\n"
"}\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"")
        self.checkBox.setObjectName("checkBox")
        self.verticalLayout_2.addWidget(self.checkBox, 0, QtCore.Qt.AlignmentFlag.AlignHCenter)
        self.pushButton = QtWidgets.QPushButton(parent=self.widget1)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.pushButton.setFont(font)
        self.pushButton.setStyleSheet("QPushButton {\n"
"         color: rgb(255, 255, 255);\n"
"         width: 80px;\n"
"           height: 30px;\n"
"         border-radius: 10px;        /* Радиус скругления краев */\n"
"         background-color: rgb(0, 196, 255);  /* Фон кнопки */\n"
"     }\n"
"     \n"
"     QPushButton:hover {\n"
"         background-color: darkgray;  /* Фон кнопки при наведении мыши */\n"
"     }\n"
"     \n"
"     QPushButton:pressed {\n"
"         background-color: darkgray;  /* Фон кнопки при нажатии */\n"
"     }")
        self.pushButton.setIconSize(QtCore.QSize(16, 16))
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout_2.addWidget(self.pushButton, 0, QtCore.Qt.AlignmentFlag.AlignHCenter)
        self.pushButton_2 = QtWidgets.QPushButton(parent=self.widget1)
        self.pushButton_2.setStyleSheet("QPushButton {\n"
"    border: none;                         /* Убираем границы */\n"
"    background-color: transparent;        /* Прозрачный фон */\n"
"    color: rgb(0, 0, 127);                /* Синий цвет текста */\n"
"    text-align: center;                     /* Текст слева */\n"
"    qproperty-icon: url(none);            /* Убираем иконку (если она есть) */\n"
"    qproperty-flat: true;                 /* Убираем 3D-эффект */\n"
"    padding: 2px 10px;                    /* Добавляем внутренние отступы */\n"
"    font: 10pt “Sans Serif”;              /* Настраиваем шрифт */\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    text-decoration: underline;           /* Подчеркивание при наведении */\n"
"}")
        self.pushButton_2.setObjectName("pushButton_2")
        self.verticalLayout_2.addWidget(self.pushButton_2)
        self.pushButton_3 = QtWidgets.QPushButton(parent=self.widget1)
        self.pushButton_3.setStyleSheet("QPushButton {\n"
"    border: none;                         /* Убираем границы */\n"
"    background-color: transparent;        /* Прозрачный фон */\n"
"    color: rgb(0, 0, 127);                /* Синий цвет текста */\n"
"    text-align: center;                     /* Текст слева */\n"
"    qproperty-icon: url(none);            /* Убираем иконку (если она есть) */\n"
"    qproperty-flat: true;                 /* Убираем 3D-эффект */\n"
"    padding: 2px 10px;                    /* Добавляем внутренние отступы */\n"
"    font: 10pt “Sans Serif”;              /* Настраиваем шрифт */\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    text-decoration: underline;           /* Подчеркивание при наведении */\n"
"}")
        self.pushButton_3.setObjectName("pushButton_3")
        self.verticalLayout_2.addWidget(self.pushButton_3)
        self.gridLayout.addWidget(self.widget, 1, 1, 1, 1)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
        self.gridLayout.addItem(spacerItem, 1, 0, 1, 1)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
        self.gridLayout.addItem(spacerItem1, 1, 2, 1, 1)
        spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
        self.gridLayout.addItem(spacerItem2, 2, 1, 1, 1)
        spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
        self.gridLayout.addItem(spacerItem3, 0, 1, 1, 1)
        Authorization.setCentralWidget(self.centralwidget)

        self.retranslateUi(Authorization)
        QtCore.QMetaObject.connectSlotsByName(Authorization)

    def retranslateUi(self, Authorization):
        _translate = QtCore.QCoreApplication.translate
        Authorization.setWindowTitle(_translate("Authorization", "MainWindow"))
        self.label.setText(_translate("Authorization", "АВТОРИЗАЦИЯ"))
        self.lineEdit.setPlaceholderText(_translate("Authorization", "Логин"))
        self.lineEdit_2.setPlaceholderText(_translate("Authorization", "Пароль"))
        self.checkBox.setText(_translate("Authorization", "запомнить меня на этом компьютере"))
        self.pushButton.setText(_translate("Authorization", "ВОЙТИ"))
        self.pushButton_2.setText(_translate("Authorization", "Забыли пароль?"))
        self.pushButton_3.setText(_translate("Authorization", "Зарегистрироваться"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Authorization = QtWidgets.QMainWindow()
    ui = Ui_Authorization()
    ui.setupUi(Authorization)
    Authorization.show()
    sys.exit(app.exec())

# Form implementation generated from reading ui file 'Registration.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_Registration(object):
    def setupUi(self, Registration):
        Registration.setObjectName("Registration")
        Registration.resize(444, 430)
        Registration.setStyleSheet("background-color: rgb(0, 196, 255);")
        self.centralwidget = QtWidgets.QWidget(parent=Registration)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.widget = QtWidgets.QWidget(parent=self.centralwidget)
        self.widget.setMinimumSize(QtCore.QSize(400, 400))
        self.widget.setMaximumSize(QtCore.QSize(400, 400))
        self.widget.setStyleSheet("QWidget {\n"
"    background-color: rgb(255, 255, 255);\n"
"    border-radius: 15px;\n"
"}\n"
"")
        self.widget.setObjectName("widget")
        self.layoutWidget = QtWidgets.QWidget(parent=self.widget)
        self.layoutWidget.setGeometry(QtCore.QRect(60, 40, 281, 311))
        self.layoutWidget.setObjectName("layoutWidget")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.layoutWidget)
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.label = QtWidgets.QLabel(parent=self.layoutWidget)
        self.label.setMinimumSize(QtCore.QSize(50, 49))
        self.label.setMaximumSize(QtCore.QSize(16777215, 50))
        font = QtGui.QFont()
        font.setPointSize(16)
        font.setBold(True)
        font.setItalic(False)
        font.setUnderline(False)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setLayoutDirection(QtCore.Qt.LayoutDirection.LeftToRight)
        self.label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout_2.addWidget(self.label)
        self.lineEdit_3 = QtWidgets.QLineEdit(parent=self.layoutWidget)
        self.lineEdit_3.setStyleSheet("QLineEdit {\n"
"    border: 2px solid darkgray;\n"
"    border-radius: 15px;\n"
"    padding: 0 8px;\n"
"    background: white;\n"
"    selection-background-color: lightblue;\n"
"    width: 30px;\n"
"    height: 30px;\n"
"}\n"
"\n"
"QLineEdit:focus {\n"
"    border: 2px solid gray; /* Цвет границы станет темнее при фокусе */\n"
"}")
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.verticalLayout_2.addWidget(self.lineEdit_3)
        self.lineEdit = QtWidgets.QLineEdit(parent=self.layoutWidget)
        self.lineEdit.setStyleSheet("QLineEdit {\n"
"    border: 2px solid darkgray;\n"
"    border-radius: 15px;\n"
"    padding: 0 8px;\n"
"    background: white;\n"
"    selection-background-color: lightblue;\n"
"    width: 30px;\n"
"    height: 30px;\n"
"}\n"
"\n"
"QLineEdit:focus {\n"
"    border: 2px solid gray; /* Цвет границы станет темнее при фокусе */\n"
"}")
        self.lineEdit.setObjectName("lineEdit")
        self.verticalLayout_2.addWidget(self.lineEdit)
        self.lineEdit_2 = QtWidgets.QLineEdit(parent=self.layoutWidget)
        self.lineEdit_2.setStyleSheet("QLineEdit {\n"
"    border: 2px solid darkgray;\n"
"    border-radius: 15px;\n"
"    padding: 0 8px;\n"
"    background: white;\n"
"    selection-background-color: lightblue;\n"
"    width: 30px;\n"
"    height: 30px;\n"
"}\n"
"\n"
"QLineEdit:focus {\n"
"    border: 2px solid gray; /* Цвет границы станет темнее при фокусе */\n"
"}")
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.verticalLayout_2.addWidget(self.lineEdit_2)
        self.lineEdit_4 = QtWidgets.QLineEdit(parent=self.layoutWidget)
        self.lineEdit_4.setStyleSheet("QLineEdit {\n"
"    border: 2px solid darkgray;\n"
"    border-radius: 15px;\n"
"    padding: 0 8px;\n"
"    background: white;\n"
"    selection-background-color: lightblue;\n"
"    width: 30px;\n"
"    height: 30px;\n"
"}\n"
"\n"
"QLineEdit:focus {\n"
"    border: 2px solid gray; /* Цвет границы станет темнее при фокусе */\n"
"}")
        self.lineEdit_4.setObjectName("lineEdit_4")
        self.verticalLayout_2.addWidget(self.lineEdit_4)
        self.pushButton = QtWidgets.QPushButton(parent=self.layoutWidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.pushButton.setFont(font)
        self.pushButton.setStyleSheet("QPushButton {\n"
"         color: rgb(255, 255, 255);\n"
"         width: 120px;\n"
"           height: 30px;\n"
"         border-radius: 10px;        /* Радиус скругления краев */\n"
"         background-color: rgb(0, 196, 255);  /* Фон кнопки */\n"
"     }\n"
"     \n"
"     QPushButton:hover {\n"
"         background-color: darkgray;  /* Фон кнопки при наведении мыши */\n"
"     }\n"
"     \n"
"     QPushButton:pressed {\n"
"         background-color: darkgray;  /* Фон кнопки при нажатии */\n"
"     }")
        self.pushButton.setIconSize(QtCore.QSize(16, 16))
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout_2.addWidget(self.pushButton, 0, QtCore.Qt.AlignmentFlag.AlignHCenter)
        self.gridLayout.addWidget(self.widget, 1, 1, 1, 1)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
        self.gridLayout.addItem(spacerItem, 1, 0, 1, 1)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
        self.gridLayout.addItem(spacerItem1, 1, 2, 1, 1)
        spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
        self.gridLayout.addItem(spacerItem2, 2, 1, 1, 1)
        spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
        self.gridLayout.addItem(spacerItem3, 0, 1, 1, 1)
        Registration.setCentralWidget(self.centralwidget)

        self.retranslateUi(Registration)
        QtCore.QMetaObject.connectSlotsByName(Registration)

    def retranslateUi(self, Registration):
        _translate = QtCore.QCoreApplication.translate
        Registration.setWindowTitle(_translate("Registration", "MainWindow"))
        self.label.setText(_translate("Registration", "РЕГИСТРАЦИЯ"))
        self.lineEdit_3.setPlaceholderText(_translate("Registration", "Электронная почта"))
        self.lineEdit.setPlaceholderText(_translate("Registration", "Логин"))
        self.lineEdit_2.setPlaceholderText(_translate("Registration", "Введите пароль"))
        self.lineEdit_4.setPlaceholderText(_translate("Registration", "Подтвердите пароль"))
        self.pushButton.setText(_translate("Registration", "СОХРАНИТЬ"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Registration = QtWidgets.QMainWindow()
    ui = Ui_Registration()
    ui.setupUi(Registration)
    Registration.show()
    sys.exit(app.exec())