-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathNo choice line edit.py
47 lines (28 loc) · 1.1 KB
/
No choice line edit.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "ipetrash"
"""
Скрипт показывает пример ограничение ввода только тем текстом, что был указан.
"""
from PyQt5.QtWidgets import *
class Widget(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("No choice")
self.line_edit_no_choice = QLineEdit()
self.line_edit_no_choice.textEdited.connect(self.on_text_edited_no_choice)
self.line_edit_source = QLineEdit("Я придурок")
self.line_edit_source.textEdited.connect(self.line_edit_no_choice.clear)
layout = QFormLayout()
layout.addRow("Скажи:", self.line_edit_source)
layout.addWidget(self.line_edit_no_choice)
self.setLayout(layout)
self.line_edit_no_choice.setFocus()
def on_text_edited_no_choice(self, text):
text = self.line_edit_source.text()[: len(text)]
self.line_edit_no_choice.setText(text)
if __name__ == "__main__":
app = QApplication([])
w = Widget()
w.show()
app.exec()