|
1 | 1 | from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton, QLineEdit,
|
2 |
| - QHBoxLayout, QMessageBox, QRadioButton, |
3 |
| - QGroupBox, QVBoxLayout) |
| 2 | + QHBoxLayout, QMessageBox, QRadioButton, |
| 3 | + QGroupBox, QVBoxLayout) |
4 | 4 | import sys
|
5 | 5 |
|
6 | 6 |
|
7 | 7 | class Window(QWidget):
|
8 |
| - def __init__(self, parent=None): |
9 |
| - super(Window, self).__init__() |
10 |
| - # first widgets |
11 |
| - self.button = QPushButton("Exibir mensagem") |
12 |
| - self.button.setAcceptDrops(True) |
13 |
| - self.button.clicked.connect(self.exibir) |
14 |
| - self.line_edit = QLineEdit() |
15 |
| - # group box of widgets |
16 |
| - self.groupbox = QGroupBox("Opções de Diálogo") |
17 |
| - # options |
18 |
| - self.option_information = QRadioButton("Information") |
19 |
| - self.option_information.setChecked(True) |
20 |
| - self.option_warning = QRadioButton("Warning") |
21 |
| - self.option_critical = QRadioButton("Critical") |
22 |
| - # layout of items of group box |
23 |
| - self.layout_options = QVBoxLayout() |
24 |
| - self.layout_options.addWidget(self.option_information) |
25 |
| - self.layout_options.addWidget(self.option_critical) |
26 |
| - self.layout_options.addWidget(self.option_warning) |
27 |
| - self.groupbox.setLayout(self.layout_options) |
28 |
| - # layout of QPushButton e QLineEdit |
29 |
| - self.layout_first_widgets = QHBoxLayout() |
30 |
| - self.layout_first_widgets.addWidget(self.line_edit) |
31 |
| - self.layout_first_widgets.addWidget(self.button) |
32 |
| - # main layout |
33 |
| - self.layout_master = QVBoxLayout() |
34 |
| - self.layout_master.addLayout(self.layout_first_widgets) |
35 |
| - self.layout_master.addWidget(self.groupbox) |
36 |
| - self.setLayout(self.layout_master) |
| 8 | + def __init__(self, parent=None): |
| 9 | + super(Window, self).__init__() |
| 10 | + # first widgets |
| 11 | + self.button = QPushButton("Exibir mensagem") |
| 12 | + self.button.setAcceptDrops(True) |
| 13 | + self.button.clicked.connect(self.exibir) |
| 14 | + self.line_edit = QLineEdit() |
| 15 | + # group box of widgets |
| 16 | + self.groupbox = QGroupBox("Opções de Diálogo") |
| 17 | + # options |
| 18 | + self.option_information = QRadioButton("Information") |
| 19 | + self.option_information.setChecked(True) |
| 20 | + self.option_warning = QRadioButton("Warning") |
| 21 | + self.option_critical = QRadioButton("Critical") |
| 22 | + # layout of items of group box |
| 23 | + self.layout_options = QVBoxLayout() |
| 24 | + self.layout_options.addWidget(self.option_information) |
| 25 | + self.layout_options.addWidget(self.option_critical) |
| 26 | + self.layout_options.addWidget(self.option_warning) |
| 27 | + self.groupbox.setLayout(self.layout_options) |
| 28 | + # layout of QPushButton e QLineEdit |
| 29 | + self.layout_first_widgets = QHBoxLayout() |
| 30 | + self.layout_first_widgets.addWidget(self.line_edit) |
| 31 | + self.layout_first_widgets.addWidget(self.button) |
| 32 | + # main layout |
| 33 | + self.layout_master = QVBoxLayout() |
| 34 | + self.layout_master.addLayout(self.layout_first_widgets) |
| 35 | + self.layout_master.addWidget(self.groupbox) |
| 36 | + self.setLayout(self.layout_master) |
37 | 37 |
|
38 |
| - def exibir(self): |
39 |
| - self.text = self.line_edit.text() |
40 |
| - if self.option_information.isChecked(): |
41 |
| - self.messsage_box = QMessageBox.information(self,"Exemplo 1", |
42 |
| - self.text) |
43 |
| - elif self.option_warning.isChecked(): |
44 |
| - self.messsage_box = QMessageBox.warning(self,"Exemplo 1", |
45 |
| - self.text) |
46 |
| - else: |
47 |
| - self.messsage_box = QMessageBox.critical(self,"Exemplo 1", |
48 |
| - self.text) |
| 38 | + def exibir(self): |
| 39 | + self.text = self.line_edit.text() |
| 40 | + if self.option_information.isChecked(): |
| 41 | + self.messsage_box = QMessageBox.information(self,"Exemplo 1", |
| 42 | + self.text) |
| 43 | + elif self.option_warning.isChecked(): |
| 44 | + self.messsage_box = QMessageBox.warning(self,"Exemplo 1", |
| 45 | + self.text) |
| 46 | + else: |
| 47 | + self.messsage_box = QMessageBox.critical(self,"Exemplo 1", |
| 48 | + self.text) |
49 | 49 |
|
50 |
| - def closeEvent(self, e): |
51 |
| - e.ignore() |
52 |
| - question_close = QMessageBox.question(self, "Fechamento", |
53 |
| - "Deseja realmente fechar a aplicação?", |
54 |
| - QMessageBox.Yes, QMessageBox.No) |
55 |
| - if question_close == QMessageBox.Yes: |
56 |
| - exit(0) |
| 50 | + def closeEvent(self, e): |
| 51 | + e.ignore() |
| 52 | + question_close = QMessageBox.question(self, "Fechamento", |
| 53 | + "Deseja realmente fechar a aplicação?", |
| 54 | + QMessageBox.Yes, QMessageBox.No) |
| 55 | + if question_close == QMessageBox.Yes: |
| 56 | + exit(0) |
57 | 57 |
|
58 | 58 | if __name__ == "__main__":
|
59 | 59 | root = QApplication([])
|
60 |
| - app = Window() |
61 |
| - app.show() |
62 |
| - sys.exit(root.exec_()) |
| 60 | + app = Window() |
| 61 | + app.show() |
| 62 | + sys.exit(root.exec_()) |
0 commit comments