Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt5.QtCore import *
- from PyQt5.QtWidgets import *
- import sys
- class Window(QWidget): # Первое окно
- def __init__(self):
- super(Window, self).__init__()
- self.setWindowTitle('iConfess')
- self.resize(250,100)
- label = QLabel('<center>Who art Thou, my child?</center>')
- line = QLineEdit() # Строка, которая будет передаваться во второе окно
- button = QPushButton('Proceed confession') # Кнопка вызова второго окна
- line.setAlignment(Qt.AlignCenter)
- vbox = QVBoxLayout()
- vbox.addWidget(label)
- vbox.addWidget(line)
- vbox.addWidget(button)
- self.setLayout(vbox)
- button.clicked.connect(self.confess)
- def confess(self): # Функция кнопки вызова второго окна
- self.showConfess = Confession()
- self.showConfess.show()
- class Confession(Window): # Второе окно
- def __init__(self):
- super(Window, self).__init__()
- self.setWindowTitle('The judgment')
- self.resize(250,100)
- label = QLabel('<center>Thou wert a good boy, ' + Window.line.text() + '!</center>') # Лейбл, в который передается строка из первого окна. Ошибка происходит именно здесь. Если убрать "+ Window.line.text()", второе окно вызовется
- button = QPushButton('Go in peace') # Кнопка закрытия второго и первого окна
- vbox = QVBoxLayout()
- vbox.addWidget(label)
- vbox.addWidget(button)
- self.setLayout(vbox)
- button.clicked.connect(self.end_app)
- def end_app(self): # Функция кнопки закрытия второго и первого окна
- self.close() # Закрывается второе окно. Успешно
- Window.close() # Закрывается первое окно. Еще одна ошибка
- app = QApplication(sys.argv)
- screen = Window()
- screen.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement