Перемещение текста с дочернего окна на Главное окно
Нужна помощь в решении следующей задачи. Есть два окна:
- первоое - главное, где есть
listWidget_users, - второе окно, где водится логин и пароль.
Задача состоит в том, чтобы с дочернего (2) окна передать текст с поля логин после нажатия на кнопку 'ДОБАВИТЬ' в главное (1) окно в listWidget_users.
В коде используется библиотека PySide6. Нужна помощь специалиста, который поможет сделать данные действия с библиотекой PySide6
main.py:
from PySide6.QtWidgets import *
from Viwe.loginWindow import LoginWindow
from Viwe.ui_main_window import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.btn_user.clicked.connect(self.open_zavdannia)
def open_zavdannia(self):
self.window2 = LoginWindow()
if __name__ == '__main__':
app = QApplication()
window = MainWindow()
window.show()
sys.exit(app.exec())
ui_main_window.py:
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QFrame, QHBoxLayout, QLayout,
QListWidget, QListWidgetItem, QMainWindow, QPlainTextEdit,
QProgressBar, QPushButton, QSizePolicy, QSpacerItem,
QVBoxLayout, QWidget)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(969, 574)
MainWindow.setLocale(QLocale(QLocale.Russian, QLocale.Russia))
MainWindow.setToolButtonStyle(Qt.ToolButtonIconOnly)
MainWindow.setAnimated(True)
self.main_frame = QWidget(MainWindow)
self.main_frame.setObjectName(u"main_frame")
self.horizontalLayout = QHBoxLayout(self.main_frame)
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.left_frame = QFrame(self.main_frame)
self.left_frame.setObjectName(u"left_frame")
self.left_frame.setMaximumSize(QSize(250, 16777215))
self.left_frame.setFrameShape(QFrame.StyledPanel)
self.left_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_4 = QVBoxLayout(self.left_frame)
self.verticalLayout_4.setSpacing(0)
self.verticalLayout_4.setObjectName(u"verticalLayout_4")
self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
self.users_frame = QFrame(self.left_frame)
self.users_frame.setObjectName(u"users_frame")
self.users_frame.setMinimumSize(QSize(0, 0))
self.users_frame.setMaximumSize(QSize(16777215, 16777215))
self.users_frame.setFrameShape(QFrame.StyledPanel)
self.users_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_8 = QVBoxLayout(self.users_frame)
self.verticalLayout_8.setSpacing(0)
self.verticalLayout_8.setObjectName(u"verticalLayout_8")
self.verticalLayout_8.setContentsMargins(2, 0, 2, 0)
self.listWidget_users = QListWidget(self.users_frame)
self.listWidget_users.setObjectName(u"listWidget_users")
self.verticalLayout_8.addWidget(self.listWidget_users)
self.verticalLayout_4.addWidget(self.users_frame)
self.buttom_frame = QFrame(self.left_frame)
self.buttom_frame.setObjectName(u"buttom_frame")
self.buttom_frame.setFrameShape(QFrame.StyledPanel)
self.buttom_frame.setFrameShadow(QFrame.Raised)
self.horizontalLayout_2 = QHBoxLayout(self.buttom_frame)
self.horizontalLayout_2.setSpacing(0)
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.add_frame = QFrame(self.buttom_frame)
self.add_frame.setObjectName(u"add_frame")
self.add_frame.setFrameShape(QFrame.StyledPanel)
self.add_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_3 = QVBoxLayout(self.add_frame)
self.verticalLayout_3.setSpacing(0)
self.verticalLayout_3.setObjectName(u"verticalLayout_3")
self.verticalLayout_3.setContentsMargins(0, 9, 9, 9)
self.btn_user = QPushButton(self.add_frame)
self.btn_user.setObjectName(u"btn_user")
self.verticalLayout_3.addWidget(self.btn_user)
self.horizontalLayout_2.addWidget(self.add_frame)
self.clear_frame = QFrame(self.buttom_frame)
self.clear_frame.setObjectName(u"clear_frame")
self.clear_frame.setFrameShape(QFrame.StyledPanel)
self.clear_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_2 = QVBoxLayout(self.clear_frame)
self.verticalLayout_2.setSpacing(0)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.verticalLayout_2.setSizeConstraint(QLayout.SetDefaultConstraint)
self.verticalLayout_2.setContentsMargins(9, 9, 0, 9)
self.btn_clear = QPushButton(self.clear_frame)
self.btn_clear.setObjectName(u"btn_clear")
self.verticalLayout_2.addWidget(self.btn_clear)
self.horizontalLayout_2.addWidget(self.clear_frame)
self.verticalLayout_4.addWidget(self.buttom_frame)
self.horizontalLayout.addWidget(self.left_frame)
self.midle_frame = QFrame(self.main_frame)
self.midle_frame.setObjectName(u"midle_frame")
self.midle_frame.setFrameShape(QFrame.StyledPanel)
self.midle_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout = QVBoxLayout(self.midle_frame)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName(u"verticalLayout")
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.log_frame = QFrame(self.midle_frame)
self.log_frame.setObjectName(u"log_frame")
self.log_frame.setMaximumSize(QSize(16777215, 16777215))
self.log_frame.setSizeIncrement(QSize(0, 0))
self.log_frame.setFrameShape(QFrame.StyledPanel)
self.log_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_5 = QVBoxLayout(self.log_frame)
self.verticalLayout_5.setSpacing(0)
self.verticalLayout_5.setObjectName(u"verticalLayout_5")
self.verticalLayout_5.setContentsMargins(2, 0, 2, 2)
self.plainTextEdit_log = QPlainTextEdit(self.log_frame)
self.plainTextEdit_log.setObjectName(u"plainTextEdit_log")
self.plainTextEdit_log.setMaximumSize(QSize(16777215, 16777215))
self.verticalLayout_5.addWidget(self.plainTextEdit_log)
self.verticalLayout.addWidget(self.log_frame)
self.bar_frame = QFrame(self.midle_frame)
self.bar_frame.setObjectName(u"bar_frame")
self.bar_frame.setFrameShape(QFrame.StyledPanel)
self.bar_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_6 = QVBoxLayout(self.bar_frame)
self.verticalLayout_6.setSpacing(0)
self.verticalLayout_6.setObjectName(u"verticalLayout_6")
self.verticalLayout_6.setContentsMargins(20, 9, 10, 9)
self.progressBar = QProgressBar(self.bar_frame)
self.progressBar.setObjectName(u"progressBar")
self.progressBar.setValue(24)
self.verticalLayout_6.addWidget(self.progressBar)
self.verticalLayout.addWidget(self.bar_frame)
self.horizontalLayout.addWidget(self.midle_frame)
self.riate_frame = QFrame(self.main_frame)
self.riate_frame.setObjectName(u"riate_frame")
self.riate_frame.setMaximumSize(QSize(16777215, 16777215))
self.riate_frame.setSizeIncrement(QSize(0, 0))
self.riate_frame.setFrameShape(QFrame.StyledPanel)
self.riate_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_7 = QVBoxLayout(self.riate_frame)
self.verticalLayout_7.setObjectName(u"verticalLayout_7")
self.verticalLayout_7.setContentsMargins(10, 9, 10, 9)
self.btn_start_scraping = QPushButton(self.riate_frame)
self.btn_start_scraping.setObjectName(u"btn_start_scraping")
self.verticalLayout_7.addWidget(self.btn_start_scraping)
self.btn_open_log = QPushButton(self.riate_frame)
self.btn_open_log.setObjectName(u"btn_open_log")
self.btn_open_log.setLocale(QLocale(QLocale.Russian, QLocale.Russia))
self.verticalLayout_7.addWidget(self.btn_open_log)
self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.verticalLayout_7.addItem(self.verticalSpacer_2)
self.horizontalLayout.addWidget(self.riate_frame)
MainWindow.setCentralWidget(self.main_frame)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
# setupUi
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
self.btn_user.setText(QCoreApplication.translate("MainWindow", u"\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c", None))
self.btn_clear.setText(QCoreApplication.translate("MainWindow", u"\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c", None))
self.plainTextEdit_log.setPlainText("")
self.btn_start_scraping.setText(QCoreApplication.translate("MainWindow", u"\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0430\u0440\u0441\u0438\u043d\u0433", None))
self.btn_open_log.setText(QCoreApplication.translate("MainWindow", u"\u041e\u0442\u043a\u0440\u044b\u0442\u044c \u043b\u043e\u0433", None))
# retranslateUi
LoginWindow.py:
from PySide6.QtWidgets import *
from Viwe.ui_login_window import Ui_LoginWindow
class LoginWindow(QMainWindow):
def __init__(self, parent=None):
super(LoginWindow, self).__init__(parent)
self.ui = Ui_LoginWindow()
self.ui.setupUi(self)
self.ui.btn_login.clicked.connect(self.addUser)
self.show()
def addUser(self):
login = self.ui.lineEdit_login.text()
passwd = self.ui.lineEdit_passwd.text()
self.close()
ui_login_window.py:
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QFrame, QHBoxLayout, QLabel,
QLineEdit, QMainWindow, QPushButton, QSizePolicy,
QVBoxLayout, QWidget)
class Ui_LoginWindow(object):
def setupUi(self, LoginWindow):
if not LoginWindow.objectName():
LoginWindow.setObjectName(u"LoginWindow")
LoginWindow.resize(338, 160)
LoginWindow.setMinimumSize(QSize(338, 160))
LoginWindow.setMaximumSize(QSize(338, 160))
self.main_login = QWidget(LoginWindow)
self.main_login.setObjectName(u"main_login")
self.main_login.setMinimumSize(QSize(338, 160))
self.main_login.setMaximumSize(QSize(338, 160))
self.verticalLayout = QVBoxLayout(self.main_login)
self.verticalLayout.setObjectName(u"verticalLayout")
self.frame_login_passwd = QFrame(self.main_login)
self.frame_login_passwd.setObjectName(u"frame_login_passwd")
self.frame_login_passwd.setFrameShape(QFrame.StyledPanel)
self.frame_login_passwd.setFrameShadow(QFrame.Raised)
self.horizontalLayout = QHBoxLayout(self.frame_login_passwd)
self.horizontalLayout.setSpacing(0)
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.frame_6 = QFrame(self.frame_login_passwd)
self.frame_6.setObjectName(u"frame_6")
self.frame_6.setFrameShape(QFrame.StyledPanel)
self.frame_6.setFrameShadow(QFrame.Raised)
self.verticalLayout_2 = QVBoxLayout(self.frame_6)
self.verticalLayout_2.setSpacing(0)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.frame_login = QFrame(self.frame_6)
self.frame_login.setObjectName(u"frame_login")
self.frame_login.setFrameShape(QFrame.StyledPanel)
self.frame_login.setFrameShadow(QFrame.Raised)
self.horizontalLayout_3 = QHBoxLayout(self.frame_login)
self.horizontalLayout_3.setSpacing(20)
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
self.horizontalLayout_3.setContentsMargins(9, 0, 9, 0)
self.label_login = QLabel(self.frame_login)
self.label_login.setObjectName(u"label_login")
self.horizontalLayout_3.addWidget(self.label_login)
self.lineEdit_login = QLineEdit(self.frame_login)
self.lineEdit_login.setObjectName(u"lineEdit_login")
self.lineEdit_login.setClearButtonEnabled(True)
self.horizontalLayout_3.addWidget(self.lineEdit_login)
self.verticalLayout_2.addWidget(self.frame_login)
self.frame_passwd = QFrame(self.frame_6)
self.frame_passwd.setObjectName(u"frame_passwd")
self.frame_passwd.setFrameShape(QFrame.StyledPanel)
self.frame_passwd.setFrameShadow(QFrame.Raised)
self.horizontalLayout_4 = QHBoxLayout(self.frame_passwd)
self.horizontalLayout_4.setSpacing(12)
self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
self.horizontalLayout_4.setContentsMargins(-1, 0, -1, 0)
self.label_passwd = QLabel(self.frame_passwd)
self.label_passwd.setObjectName(u"label_passwd")
self.horizontalLayout_4.addWidget(self.label_passwd)
self.lineEdit_passwd = QLineEdit(self.frame_passwd)
self.lineEdit_passwd.setObjectName(u"lineEdit_passwd")
self.lineEdit_passwd.setEchoMode(QLineEdit.Password)
self.lineEdit_passwd.setDragEnabled(False)
self.lineEdit_passwd.setClearButtonEnabled(True)
self.horizontalLayout_4.addWidget(self.lineEdit_passwd)
self.verticalLayout_2.addWidget(self.frame_passwd)
self.horizontalLayout.addWidget(self.frame_6)
self.verticalLayout.addWidget(self.frame_login_passwd)
self.frame_btn = QFrame(self.main_login)
self.frame_btn.setObjectName(u"frame_btn")
self.frame_btn.setFrameShape(QFrame.StyledPanel)
self.frame_btn.setFrameShadow(QFrame.Raised)
self.horizontalLayout_2 = QHBoxLayout(self.frame_btn)
self.horizontalLayout_2.setSpacing(0)
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.frame_add = QFrame(self.frame_btn)
self.frame_add.setObjectName(u"frame_add")
self.frame_add.setFrameShape(QFrame.StyledPanel)
self.frame_add.setFrameShadow(QFrame.Raised)
self.verticalLayout_4 = QVBoxLayout(self.frame_add)
self.verticalLayout_4.setSpacing(0)
self.verticalLayout_4.setObjectName(u"verticalLayout_4")
self.verticalLayout_4.setContentsMargins(9, 0, 9, 0)
self.btn_login = QPushButton(self.frame_add)
self.btn_login.setObjectName(u"btn_login")
self.verticalLayout_4.addWidget(self.btn_login)
self.horizontalLayout_2.addWidget(self.frame_add)
self.frame_clear = QFrame(self.frame_btn)
self.frame_clear.setObjectName(u"frame_clear")
self.frame_clear.setFrameShape(QFrame.StyledPanel)
self.frame_clear.setFrameShadow(QFrame.Raised)
self.verticalLayout_5 = QVBoxLayout(self.frame_clear)
self.verticalLayout_5.setSpacing(0)
self.verticalLayout_5.setObjectName(u"verticalLayout_5")
self.verticalLayout_5.setContentsMargins(-1, 0, -1, 0)
self.btn_clear = QPushButton(self.frame_clear)
self.btn_clear.setObjectName(u"btn_clear")
self.verticalLayout_5.addWidget(self.btn_clear)
self.horizontalLayout_2.addWidget(self.frame_clear)
self.verticalLayout.addWidget(self.frame_btn)
LoginWindow.setCentralWidget(self.main_login)
self.retranslateUi(LoginWindow)
QMetaObject.connectSlotsByName(LoginWindow)
# setupUi
def retranslateUi(self, LoginWindow):
LoginWindow.setWindowTitle(QCoreApplication.translate("LoginWindow", u"Log In", None))
self.label_login.setText(QCoreApplication.translate("LoginWindow", u"\u041b\u043e\u0433\u0438\u043d", None))
self.label_passwd.setText(QCoreApplication.translate("LoginWindow", u"\u041f\u0430\u0440\u043e\u043b\u044c", None))
self.btn_login.setText(QCoreApplication.translate("LoginWindow", u"\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c", None))
self.btn_clear.setText(QCoreApplication.translate("LoginWindow", u"\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c", None))
# retranslateUi
Ответы (1 шт):
Автор решения: S. Nick
→ Ссылка
При создании экземпляра второго окна передайте ссылку на первое окно:
self.window2 = LoginWindow(self)
# ^^^^
и в методе addUser() модуля loginWindow.py:
self.parent.ui.listWidget_users.addItem(login)
main.py
'''
from PySide6.QtWidgets import *
'''
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.Qt import *
from loginWindow import LoginWindow
#from Viwe.ui_main_window import Ui_MainWindow
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(969, 574)
MainWindow.setLocale(QLocale(QLocale.Russian, QLocale.Russia))
MainWindow.setToolButtonStyle(Qt.ToolButtonIconOnly)
MainWindow.setAnimated(True)
self.main_frame = QWidget(MainWindow)
self.main_frame.setObjectName(u"main_frame")
self.horizontalLayout = QHBoxLayout(self.main_frame)
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.left_frame = QFrame(self.main_frame)
self.left_frame.setObjectName(u"left_frame")
self.left_frame.setMaximumSize(QSize(250, 16777215))
self.left_frame.setFrameShape(QFrame.StyledPanel)
self.left_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_4 = QVBoxLayout(self.left_frame)
self.verticalLayout_4.setSpacing(0)
self.verticalLayout_4.setObjectName(u"verticalLayout_4")
self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
self.users_frame = QFrame(self.left_frame)
self.users_frame.setObjectName(u"users_frame")
self.users_frame.setMinimumSize(QSize(0, 0))
self.users_frame.setMaximumSize(QSize(16777215, 16777215))
self.users_frame.setFrameShape(QFrame.StyledPanel)
self.users_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_8 = QVBoxLayout(self.users_frame)
self.verticalLayout_8.setSpacing(0)
self.verticalLayout_8.setObjectName(u"verticalLayout_8")
self.verticalLayout_8.setContentsMargins(2, 0, 2, 0)
self.listWidget_users = QListWidget(self.users_frame)
self.listWidget_users.setObjectName(u"listWidget_users")
self.verticalLayout_8.addWidget(self.listWidget_users)
self.verticalLayout_4.addWidget(self.users_frame)
self.buttom_frame = QFrame(self.left_frame)
self.buttom_frame.setObjectName(u"buttom_frame")
self.buttom_frame.setFrameShape(QFrame.StyledPanel)
self.buttom_frame.setFrameShadow(QFrame.Raised)
self.horizontalLayout_2 = QHBoxLayout(self.buttom_frame)
self.horizontalLayout_2.setSpacing(0)
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.add_frame = QFrame(self.buttom_frame)
self.add_frame.setObjectName(u"add_frame")
self.add_frame.setFrameShape(QFrame.StyledPanel)
self.add_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_3 = QVBoxLayout(self.add_frame)
self.verticalLayout_3.setSpacing(0)
self.verticalLayout_3.setObjectName(u"verticalLayout_3")
self.verticalLayout_3.setContentsMargins(0, 9, 9, 9)
self.btn_user = QPushButton(self.add_frame)
self.btn_user.setObjectName(u"btn_user")
self.verticalLayout_3.addWidget(self.btn_user)
self.horizontalLayout_2.addWidget(self.add_frame)
self.clear_frame = QFrame(self.buttom_frame)
self.clear_frame.setObjectName(u"clear_frame")
self.clear_frame.setFrameShape(QFrame.StyledPanel)
self.clear_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_2 = QVBoxLayout(self.clear_frame)
self.verticalLayout_2.setSpacing(0)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.verticalLayout_2.setSizeConstraint(QLayout.SetDefaultConstraint)
self.verticalLayout_2.setContentsMargins(9, 9, 0, 9)
self.btn_clear = QPushButton(self.clear_frame)
self.btn_clear.setObjectName(u"btn_clear")
self.verticalLayout_2.addWidget(self.btn_clear)
self.horizontalLayout_2.addWidget(self.clear_frame)
self.verticalLayout_4.addWidget(self.buttom_frame)
self.horizontalLayout.addWidget(self.left_frame)
self.midle_frame = QFrame(self.main_frame)
self.midle_frame.setObjectName(u"midle_frame")
self.midle_frame.setFrameShape(QFrame.StyledPanel)
self.midle_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout = QVBoxLayout(self.midle_frame)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName(u"verticalLayout")
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.log_frame = QFrame(self.midle_frame)
self.log_frame.setObjectName(u"log_frame")
self.log_frame.setMaximumSize(QSize(16777215, 16777215))
self.log_frame.setSizeIncrement(QSize(0, 0))
self.log_frame.setFrameShape(QFrame.StyledPanel)
self.log_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_5 = QVBoxLayout(self.log_frame)
self.verticalLayout_5.setSpacing(0)
self.verticalLayout_5.setObjectName(u"verticalLayout_5")
self.verticalLayout_5.setContentsMargins(2, 0, 2, 2)
self.plainTextEdit_log = QPlainTextEdit(self.log_frame)
self.plainTextEdit_log.setObjectName(u"plainTextEdit_log")
self.plainTextEdit_log.setMaximumSize(QSize(16777215, 16777215))
self.verticalLayout_5.addWidget(self.plainTextEdit_log)
self.verticalLayout.addWidget(self.log_frame)
self.bar_frame = QFrame(self.midle_frame)
self.bar_frame.setObjectName(u"bar_frame")
self.bar_frame.setFrameShape(QFrame.StyledPanel)
self.bar_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_6 = QVBoxLayout(self.bar_frame)
self.verticalLayout_6.setSpacing(0)
self.verticalLayout_6.setObjectName(u"verticalLayout_6")
self.verticalLayout_6.setContentsMargins(20, 9, 10, 9)
self.progressBar = QProgressBar(self.bar_frame)
self.progressBar.setObjectName(u"progressBar")
self.progressBar.setValue(24)
self.verticalLayout_6.addWidget(self.progressBar)
self.verticalLayout.addWidget(self.bar_frame)
self.horizontalLayout.addWidget(self.midle_frame)
self.riate_frame = QFrame(self.main_frame)
self.riate_frame.setObjectName(u"riate_frame")
self.riate_frame.setMaximumSize(QSize(16777215, 16777215))
self.riate_frame.setSizeIncrement(QSize(0, 0))
self.riate_frame.setFrameShape(QFrame.StyledPanel)
self.riate_frame.setFrameShadow(QFrame.Raised)
self.verticalLayout_7 = QVBoxLayout(self.riate_frame)
self.verticalLayout_7.setObjectName(u"verticalLayout_7")
self.verticalLayout_7.setContentsMargins(10, 9, 10, 9)
self.btn_start_scraping = QPushButton(self.riate_frame)
self.btn_start_scraping.setObjectName(u"btn_start_scraping")
self.verticalLayout_7.addWidget(self.btn_start_scraping)
self.btn_open_log = QPushButton(self.riate_frame)
self.btn_open_log.setObjectName(u"btn_open_log")
self.btn_open_log.setLocale(QLocale(QLocale.Russian, QLocale.Russia))
self.verticalLayout_7.addWidget(self.btn_open_log)
self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.verticalLayout_7.addItem(self.verticalSpacer_2)
self.horizontalLayout.addWidget(self.riate_frame)
MainWindow.setCentralWidget(self.main_frame)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
self.btn_user.setText(QCoreApplication.translate("MainWindow", u"\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c", None))
self.btn_clear.setText(QCoreApplication.translate("MainWindow", u"\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c", None))
self.plainTextEdit_log.setPlainText("")
self.btn_start_scraping.setText(QCoreApplication.translate("MainWindow", u"\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0430\u0440\u0441\u0438\u043d\u0433", None))
self.btn_open_log.setText(QCoreApplication.translate("MainWindow", u"\u041e\u0442\u043a\u0440\u044b\u0442\u044c \u043b\u043e\u0433", None))
# retranslateUi
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.btn_user.clicked.connect(self.open_zavdannia)
self.ui.listWidget_users.itemClicked.connect(self.item_clicked)
# +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
def item_clicked(self, item):
QMessageBox.information(
self,
"ListWidget",
f"You clicked: {item.text()}"
)
# +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
def open_zavdannia(self):
self.window2 = LoginWindow(self) # !!! +++ (self)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
loginWindow.py
'''
from PySide6.QtWidgets import *
'''
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.Qt import *
#from Viwe.ui_login_window import Ui_LoginWindow
class Ui_LoginWindow(object):
def setupUi(self, LoginWindow):
if not LoginWindow.objectName():
LoginWindow.setObjectName(u"LoginWindow")
LoginWindow.resize(338, 160)
LoginWindow.setMinimumSize(QSize(338, 160))
LoginWindow.setMaximumSize(QSize(338, 160))
self.main_login = QWidget(LoginWindow)
self.main_login.setObjectName(u"main_login")
self.main_login.setMinimumSize(QSize(338, 160))
self.main_login.setMaximumSize(QSize(338, 160))
self.verticalLayout = QVBoxLayout(self.main_login)
self.verticalLayout.setObjectName(u"verticalLayout")
self.frame_login_passwd = QFrame(self.main_login)
self.frame_login_passwd.setObjectName(u"frame_login_passwd")
self.frame_login_passwd.setFrameShape(QFrame.StyledPanel)
self.frame_login_passwd.setFrameShadow(QFrame.Raised)
self.horizontalLayout = QHBoxLayout(self.frame_login_passwd)
self.horizontalLayout.setSpacing(0)
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.frame_6 = QFrame(self.frame_login_passwd)
self.frame_6.setObjectName(u"frame_6")
self.frame_6.setFrameShape(QFrame.StyledPanel)
self.frame_6.setFrameShadow(QFrame.Raised)
self.verticalLayout_2 = QVBoxLayout(self.frame_6)
self.verticalLayout_2.setSpacing(0)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.frame_login = QFrame(self.frame_6)
self.frame_login.setObjectName(u"frame_login")
self.frame_login.setFrameShape(QFrame.StyledPanel)
self.frame_login.setFrameShadow(QFrame.Raised)
self.horizontalLayout_3 = QHBoxLayout(self.frame_login)
self.horizontalLayout_3.setSpacing(20)
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
self.horizontalLayout_3.setContentsMargins(9, 0, 9, 0)
self.label_login = QLabel(self.frame_login)
self.label_login.setObjectName(u"label_login")
self.horizontalLayout_3.addWidget(self.label_login)
self.lineEdit_login = QLineEdit(self.frame_login)
self.lineEdit_login.setObjectName(u"lineEdit_login")
self.lineEdit_login.setClearButtonEnabled(True)
self.horizontalLayout_3.addWidget(self.lineEdit_login)
self.verticalLayout_2.addWidget(self.frame_login)
self.frame_passwd = QFrame(self.frame_6)
self.frame_passwd.setObjectName(u"frame_passwd")
self.frame_passwd.setFrameShape(QFrame.StyledPanel)
self.frame_passwd.setFrameShadow(QFrame.Raised)
self.horizontalLayout_4 = QHBoxLayout(self.frame_passwd)
self.horizontalLayout_4.setSpacing(12)
self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
self.horizontalLayout_4.setContentsMargins(-1, 0, -1, 0)
self.label_passwd = QLabel(self.frame_passwd)
self.label_passwd.setObjectName(u"label_passwd")
self.horizontalLayout_4.addWidget(self.label_passwd)
self.lineEdit_passwd = QLineEdit(self.frame_passwd)
self.lineEdit_passwd.setObjectName(u"lineEdit_passwd")
self.lineEdit_passwd.setEchoMode(QLineEdit.Password)
self.lineEdit_passwd.setDragEnabled(False)
self.lineEdit_passwd.setClearButtonEnabled(True)
self.horizontalLayout_4.addWidget(self.lineEdit_passwd)
self.verticalLayout_2.addWidget(self.frame_passwd)
self.horizontalLayout.addWidget(self.frame_6)
self.verticalLayout.addWidget(self.frame_login_passwd)
self.frame_btn = QFrame(self.main_login)
self.frame_btn.setObjectName(u"frame_btn")
self.frame_btn.setFrameShape(QFrame.StyledPanel)
self.frame_btn.setFrameShadow(QFrame.Raised)
self.horizontalLayout_2 = QHBoxLayout(self.frame_btn)
self.horizontalLayout_2.setSpacing(0)
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.frame_add = QFrame(self.frame_btn)
self.frame_add.setObjectName(u"frame_add")
self.frame_add.setFrameShape(QFrame.StyledPanel)
self.frame_add.setFrameShadow(QFrame.Raised)
self.verticalLayout_4 = QVBoxLayout(self.frame_add)
self.verticalLayout_4.setSpacing(0)
self.verticalLayout_4.setObjectName(u"verticalLayout_4")
self.verticalLayout_4.setContentsMargins(9, 0, 9, 0)
self.btn_login = QPushButton(self.frame_add)
self.btn_login.setObjectName(u"btn_login")
self.verticalLayout_4.addWidget(self.btn_login)
self.horizontalLayout_2.addWidget(self.frame_add)
self.frame_clear = QFrame(self.frame_btn)
self.frame_clear.setObjectName(u"frame_clear")
self.frame_clear.setFrameShape(QFrame.StyledPanel)
self.frame_clear.setFrameShadow(QFrame.Raised)
self.verticalLayout_5 = QVBoxLayout(self.frame_clear)
self.verticalLayout_5.setSpacing(0)
self.verticalLayout_5.setObjectName(u"verticalLayout_5")
self.verticalLayout_5.setContentsMargins(-1, 0, -1, 0)
self.btn_clear = QPushButton(self.frame_clear)
self.btn_clear.setObjectName(u"btn_clear")
self.verticalLayout_5.addWidget(self.btn_clear)
self.horizontalLayout_2.addWidget(self.frame_clear)
self.verticalLayout.addWidget(self.frame_btn)
LoginWindow.setCentralWidget(self.main_login)
self.retranslateUi(LoginWindow)
QMetaObject.connectSlotsByName(LoginWindow)
def retranslateUi(self, LoginWindow):
LoginWindow.setWindowTitle(QCoreApplication.translate("LoginWindow", u"Log In", None))
self.label_login.setText(QCoreApplication.translate("LoginWindow", u"\u041b\u043e\u0433\u0438\u043d", None))
self.label_passwd.setText(QCoreApplication.translate("LoginWindow", u"\u041f\u0430\u0440\u043e\u043b\u044c", None))
self.btn_login.setText(QCoreApplication.translate("LoginWindow", u"\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c", None))
self.btn_clear.setText(QCoreApplication.translate("LoginWindow", u"\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c", None))
class LoginWindow(QMainWindow):
def __init__(self, parent=None):
super(LoginWindow, self).__init__(parent)
self.ui = Ui_LoginWindow()
self.ui.setupUi(self)
self.parent = parent # !!! +++
self.ui.btn_login.clicked.connect(self.addUser)
self.show()
def addUser(self):
login = self.ui.lineEdit_login.text()
passwd = self.ui.lineEdit_passwd.text()
self.parent.ui.listWidget_users.addItem(login) # !!! +++
self.close()

