Advertisement
Guest User

cryForHelp.py

a guest
Jun 25th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.15 KB | None | 0 0
  1. from PyQt5.QtCore import *
  2. from PyQt5.QtWidgets import *
  3. import sys
  4.  
  5. class Window(QWidget):                                                                              # Первое окно
  6.     def __init__(self):
  7.         super(Window, self).__init__()
  8.         self.setWindowTitle('iConfess')
  9.         self.resize(250,100)
  10.        
  11.         label = QLabel('<center>Who art Thou, my child?</center>')
  12.         line = QLineEdit()                                                                          # Строка, которая будет передаваться во второе окно
  13.         button = QPushButton('Proceed confession')                                                  # Кнопка вызова второго окна
  14.        
  15.         line.setAlignment(Qt.AlignCenter)
  16.        
  17.         vbox = QVBoxLayout()
  18.         vbox.addWidget(label)
  19.         vbox.addWidget(line)
  20.         vbox.addWidget(button)
  21.         self.setLayout(vbox)
  22.                
  23.         button.clicked.connect(self.confess)
  24.        
  25.        
  26.     def confess(self):                                                                              # Функция кнопки вызова второго окна
  27.         self.showConfess = Confession()
  28.         self.showConfess.show()
  29.  
  30.  
  31. class Confession(Window):                                                                           # Второе окно
  32.     def __init__(self):
  33.         super(Window, self).__init__()
  34.         self.setWindowTitle('The judgment')
  35.         self.resize(250,100)
  36.        
  37.         label = QLabel('<center>Thou wert a good boy, ' + Window.line.text() + '!</center>')        # Лейбл, в который передается строка из первого окна. Ошибка происходит именно здесь. Если убрать "+ Window.line.text()", второе окно вызовется
  38.         button = QPushButton('Go in peace')                                                         # Кнопка закрытия второго и первого окна
  39.        
  40.         vbox = QVBoxLayout()
  41.         vbox.addWidget(label)
  42.         vbox.addWidget(button)
  43.         self.setLayout(vbox)
  44.                
  45.         button.clicked.connect(self.end_app)
  46.        
  47.     def end_app(self):                                                                              # Функция кнопки закрытия второго и первого окна
  48.         self.close()                                                                                # Закрывается второе окно. Успешно
  49.         Window.close()                                                                              # Закрывается первое окно. Еще одна ошибка
  50.        
  51.  
  52. app = QApplication(sys.argv)
  53.  
  54. screen = Window()
  55. screen.show()
  56.  
  57. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement