Answer the question
In order to leave comments, you need to log in
PyQt5. How to switch between windows by passing data?
I need to launch another from one window by passing the login variable. How it is possible to implement it?
Here is the code (stripped down):
class LogWin(QtWidgets.QMainWindow, Login):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pushButton.pressed.connect(self.login)
def error(self):
QMessageBox.about(self, "Error", "Логин неверный.")
def login(self):
login = self.lineEdit.text()
response = requests.get('http://127.0.0.1:5000/login')
logins = response.json()['logins']
if login in logins:
self.hide()
clien.start(login)
else:
self.error()
self.lineEdit.clear()
class Messenger(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, login):
super().__init__()
self.setupUi(self)
self.label_3 = login
def start(login):
app = QtWidgets.QApplication([])
window = Messenger(login=login)
window.show()
app.exec()
reg = QtWidgets.QApplication([])
regwin = LogWin()
regwin.show()
reg.exec()
Answer the question
In order to leave comments, you need to log in
Solution:
class LogWin(QtWidgets.QMainWindow, Login):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pushButton.pressed.connect(self.login)
def error(self):
QMessageBox.about(self, "Error", "Логин неверный.")
def login(self):
login = self.lineEdit.text()
response = requests.get('http://127.0.0.1:5000/login')
logins = response.json()['logins']
if login in logins:
self.hide()
self.window = Messenger(login = login)
self.window.show()
else:
self.error()
self.lineEdit.clear()
reg = QtWidgets.QApplication([])
regwin = LogWin()
regwin.show()
reg.exec()
class Messenger(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, login):
super().__init__()
self.setupUi(self)
self.label_3.setText(login)
self.label_3 = login
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question