-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwindow10_signal_slot.py
40 lines (31 loc) · 970 Bytes
/
window10_signal_slot.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
#!/usr/bin/env python3
from PyQt5 import QtWidgets
import sys
import random
"""
Signal-Slot: Send a signal when the user interacts with a slot.
"""
def create_window():
# Define window:
obj = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
# Set window attributes:
window.setWindowTitle("My PyQt5 Interface")
window.setGeometry(250, 100, 600, 300) # upper left corner of monitor is ax = ay = 0.
# Create some GUI:
line = QtWidgets.QLineEdit(window)
line.setText("Robot velocity")
line.setReadOnly(True)
button = QtWidgets.QPushButton(window)
button.move(0, 25)
button.setText("Track robot")
# Signal-Slot:
def buttonCallback():
robot_vel = random.gauss(5, 0.3)
line.setText("{:.2f} m/s".format(robot_vel))
button.clicked.connect(buttonCallback)
# Display window:
window.show()
sys.exit(obj.exec_())
if __name__ == "__main__":
create_window()