front класса MessageWindow:
from PySide2 import QtCore, QtGui, QtWidgets
class Ui_message_window(object):
def setupUi(self, message_window):
message_window.setObjectName("message_window")
message_window.resize(506, 286)
message_window.setMinimumSize(QtCore.QSize(506, 236))
message_window.setMaximumSize(QtCore.QSize(506, 286))
self.line_title = QtWidgets.QLineEdit(message_window)
self.line_title.setGeometry(QtCore.QRect(90, 10, 411, 31))
self.line_title.setMinimumSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(20)
self.line_title.setFont(font)
self.line_title.setObjectName("line_title")
self.label = QtWidgets.QLabel(message_window)
self.label.setGeometry(QtCore.QRect(10, 10, 91, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(20)
self.label.setFont(font)
self.label.setObjectName("label")
self.window_text = QtWidgets.QTextEdit(message_window)
self.window_text.setGeometry(QtCore.QRect(10, 50, 491, 181))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(16)
self.window_text.setFont(font)
self.window_text.setObjectName("window_text")
self.button_confirm = QtWidgets.QPushButton(message_window)
self.button_confirm.setGeometry(QtCore.QRect(10, 240, 491, 41))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(20)
self.button_confirm.setFont(font)
self.button_confirm.setObjectName("button_confirm")
self.retranslateUi(message_window)
QtCore.QMetaObject.connectSlotsByName(message_window)
def retranslateUi(self, message_window):
message_window.setWindowTitle(QtWidgets.QApplication.translate("message_window", "Form", None, -1))
self.label.setText(QtWidgets.QApplication.translate("message_window", "Title", None, -1))
self.button_confirm.setText(QtWidgets.QApplication.translate("message_window", "Confirm", None, -1))
front класса Main:
from PySide2 import QtCore, QtGui, QtWidgets
class Ui_NoteList(object):
def setupUi(self, NoteList):
NoteList.setObjectName("NoteList")
NoteList.resize(560, 645)
NoteList.setMinimumSize(QtCore.QSize(560, 645))
NoteList.setMaximumSize(QtCore.QSize(560, 645))
self.centralwidget = QtWidgets.QWidget(NoteList)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 10, 171, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(20)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(10, 50, 161, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(20)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.line_login = QtWidgets.QLineEdit(self.centralwidget)
self.line_login.setGeometry(QtCore.QRect(180, 10, 201, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(20)
self.line_login.setFont(font)
self.line_login.setObjectName("line_login")
self.line_password = QtWidgets.QLineEdit(self.centralwidget)
self.line_password.setGeometry(QtCore.QRect(180, 50, 201, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(20)
self.line_password.setFont(font)
self.line_password.setObjectName("line_password")
self.button_log = QtWidgets.QPushButton(self.centralwidget)
self.button_log.setGeometry(QtCore.QRect(390, 10, 161, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(16)
self.button_log.setFont(font)
self.button_log.setObjectName("button_log")
self.button_sign = QtWidgets.QPushButton(self.centralwidget)
self.button_sign.setGeometry(QtCore.QRect(390, 50, 161, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(16)
self.button_sign.setFont(font)
self.button_sign.setObjectName("button_sign")
self.button_add = QtWidgets.QPushButton(self.centralwidget)
self.button_add.setGeometry(QtCore.QRect(10, 90, 161, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(16)
self.button_add.setFont(font)
self.button_add.setObjectName("button_add")
self.button_delete = QtWidgets.QPushButton(self.centralwidget)
self.button_delete.setGeometry(QtCore.QRect(180, 90, 201, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(16)
self.button_delete.setFont(font)
self.button_delete.setObjectName("button_delete")
self.button_edit = QtWidgets.QPushButton(self.centralwidget)
self.button_edit.setGeometry(QtCore.QRect(390, 90, 161, 31))
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(16)
self.button_edit.setFont(font)
self.button_edit.setObjectName("button_edit")
self.table_w = QtWidgets.QTableWidget(self.centralwidget)
self.table_w.setGeometry(QtCore.QRect(10, 130, 541, 491))
self.table_w.setObjectName("table_w")
self.table_w.setColumnCount(3)
self.table_w.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.table_w.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.table_w.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.table_w.setHorizontalHeaderItem(2, item)
NoteList.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(NoteList)
self.statusbar.setObjectName("statusbar")
NoteList.setStatusBar(self.statusbar)
self.retranslateUi(NoteList)
QtCore.QMetaObject.connectSlotsByName(NoteList)
def retranslateUi(self, NoteList):
NoteList.setWindowTitle(QtWidgets.QApplication.translate("NoteList", "MainWindow", None, -1))
self.label.setText(QtWidgets.QApplication.translate("NoteList", "LOGIN", None, -1))
self.label_2.setText(QtWidgets.QApplication.translate("NoteList", "PASSWORD", None, -1))
self.button_log.setText(QtWidgets.QApplication.translate("NoteList", "LOG IN", None, -1))
self.button_sign.setText(QtWidgets.QApplication.translate("NoteList", "SIGN UP", None, -1))
self.button_add.setText(QtWidgets.QApplication.translate("NoteList", "ADD", None, -1))
self.button_delete.setText(QtWidgets.QApplication.translate("NoteList", "DELETE", None, -1))
self.button_edit.setText(QtWidgets.QApplication.translate("NoteList", "EDIT", None, -1))
self.table_w.horizontalHeaderItem(0).setText(QtWidgets.QApplication.translate("NoteList", "Date", None, -1))
self.table_w.horizontalHeaderItem(1).setText(QtWidgets.QApplication.translate("NoteList", "Title", None, -1))
self.table_w.horizontalHeaderItem(2).setText(QtWidgets.QApplication.translate("NoteList", "Text", None, -1))
main.py:
from frontend import *
from front_reg import Ui_reg_window
from message_window import Ui_message_window
from PySide2.QtWidgets import QMessageBox
from xml.etree import ElementTree as ET
import sys
class MessageWindow(QtWidgets.QWidget, Ui_message_window):
def __init__(self, parent=None):
super(MessageWindow, self).__init__(parent)
self.setupUi(self)
self.parent = parent
self.button_confirm.clicked.connect(self.buttonConfirm)
def buttonConfirm(self):
self.parent.title = self.line_title.text()
self.parent.text = self.window_text.toPlainText()
class Main(QtWidgets.QMainWindow, Ui_NoteList):
LOGGED = False
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.setupUi(self)
# try:
# tree = ET.parse('data.xml')
# self.root = tree.getroot()
# except:
# with open('data.xml'):
# root = ET.Element('datalist')
# tree = ET.ElementTree(root)
# tree.write('data.xml')
# self.root = ET.parse('data.xml').getroot()
self.table_w.setRowCount(15)
self.table_w.setColumnCount(3)
self.table_w.horizontalHeader().setStretchLastSection(True)
# Установите ширину нужного вам столбца
self.table_w.setColumnWidth(0, 70)
self.table_w.setColumnWidth(1, 100)
# Это свойство содержит политику переноса текста в элементе
self.table_w.setWordWrap(False)
# self.table_w.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
# self.table_w.setItem(0, 0, QtWidgets.QTableWidgetItem("12.12.3012"))
# self.table_w.setItem(0, 1, QtWidgets.QTableWidgetItem("Редактирование невозможно."))
self.table_w.verticalHeader().setDefaultSectionSize(33)
self.table_w.setAlternatingRowColors(True)
self.line_password.setEchoMode(QtWidgets.QLineEdit.Password)
self.line_password.setMaxLength(13)
self.button_log.clicked.connect(self.buttonLog)
self.button_sign.clicked.connect(self.buttonReg)
self.button_add.clicked.connect(self.buttonAdd)
# def buttonLog(self):
# self.login = self.line_login.text()
# self.password = self.line_password.text()
# for person in self.root.iter('person'):
# if self.login not in [person.attrib['login'] for person in self.root.iter('person')]:
# message = QtWidgets.QMessageBox()
# message.setWindowTitle('Bad')
# message.setText('Wrong login')
# message.setIcon(message.Warning)
# message.exec()
# break
# if person.attrib['login'] == self.login and person.attrib['password'] == self.password:
# message = QtWidgets.QMessageBox()
# message.setWindowTitle('Good')
# message.setText('Log In Successful')
# message.setIcon(message.Information)
# message.exec()
# self.LOGGED = True
# break
# def buttonReg(self):
# self.window = RegWindow()
# self.window.show()
# # print(self.window.login, self.window.password)
def buttonAdd(self):
self.win = MessageWindow()
self.win.show()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
win = Main()
win.show()
sys.exit(app.exec_())
Суть: при нажатии ADD открывается окно, в котором можно ввести заголовок и текст заметки.
Что мне хотелось бы получить: чтобы при нажатии Confirm в открывшемся окне класса MessageWindow, вызванного из класса Main, в этот класс Main в переменную записался текст из двух окон класса MessageWindow, а именно
self.title = lineEdit из MessageWindow
self.text = textView из MessageWindow
То есть когда пользователь введет заметку и нажмет подтвердить, тайтл и текст заметки сохранились в классе Main
для дальнейшей работы.