-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyqt_example.py
43 lines (32 loc) · 1.19 KB
/
pyqt_example.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QVBoxLayout, QWidget
import sys
class ExampleApp(QMainWindow):
def __init__(self):
super().__init__()
# initialize the UI
self.init_ui()
def init_ui(self):
# create a central widget and set it as the main window's central widget
central_widget = QWidget()
self.setCentralWidget(central_widget)
# create a vertical layout
layout = QVBoxLayout()
# create a label
self.label = QLabel("Hello, PyQt!")
layout.addWidget(self.label)
# create a button and connect it to the slot method
button = QPushButton("Click Me")
button.clicked.connect(self.on_button_click)
layout.addWidget(button)
# set the layout on the central widget
central_widget.setLayout(layout)
# set main window properties
self.setWindowTitle('PyQt Example')
self.setGeometry(100, 100, 300, 200)
def on_button_click(self):
self.label.setText("Button Clicked!")
if __name__ == '__main__':
app = QApplication(sys.argv)
main_win = ExampleApp()
main_win.show()
sys.exit(app.exec_())