-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpush_button.py
More file actions
28 lines (21 loc) · 955 Bytes
/
Copy pathpush_button.py
File metadata and controls
28 lines (21 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
from PyQt5 import QtWidgets
class MyWindow(QtWidgets.QWidget):
def __init__(self):
QtWidgets.QWidget.__init__(self)
self.resize(300, 100)
self.setWindowTitle("Hello")
self.box_layout = QtWidgets.QHBoxLayout() # Создаем BoxLayout layout
self.button = QtWidgets.QPushButton()
self.button.setText('Button')
self.button.clicked.connect(self.click)
self.box_layout.addWidget(self.button) # Добавляем на layout кнопку
self.setLayout(self.box_layout) # Устанавливаем окну layout
def click(self): # Метод обработки нажатия на кнопку
self.button.setText('Кнопка нажата!')
self.setWindowTitle('Кнопка нажата!')
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())