-
Notifications
You must be signed in to change notification settings - Fork 0
/
08_labels_lineedit.py
51 lines (38 loc) · 1.42 KB
/
08_labels_lineedit.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
44
45
46
47
48
49
50
51
import sys
from PySide6.QtWidgets import QApplication, QWidget, QLineEdit, QHBoxLayout, QVBoxLayout, QLabel, QPushButton
class Widget(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Labels and LineEdits")
label = QLabel("Name: ", self)
self.line_edit = QLineEdit()
self.line_edit.textChanged.connect(self.on_text_changed)
self.line_edit.cursorPositionChanged.connect(self.on_cursor_changed)
button = QPushButton("Get data")
button.clicked.connect(self.on_button_clicked)
self.holder_label = QLabel("HERE")
h_layout = QHBoxLayout()
h_layout.addWidget(label)
h_layout.addWidget(self.line_edit)
v_layout = QVBoxLayout()
v_layout.addLayout(h_layout)
v_layout.addWidget(button)
v_layout.addWidget(self.holder_label)
self.setLayout(v_layout)
def on_button_clicked(self):
text = self.line_edit.text().strip()
if not text: return
self.holder_label.setText(text)
print("Name entered:", text)
def on_text_changed(self):
text = self.line_edit.text().strip()
if not text: return
self.holder_label.setText(text)
def on_cursor_changed(self, old, new):
print("old: ", old)
print("new: ", new)
if __name__=='__main__':
app = QApplication(sys.argv)
widget = Widget()
widget.show()
app.exec()