-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04 text Boxes.py
More file actions
50 lines (36 loc) · 1.27 KB
/
Copy path04 text Boxes.py
File metadata and controls
50 lines (36 loc) · 1.27 KB
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
import sys
import PyQt5.QtWidgets as qtw
import PyQt5.QtGui as qtg
class MainWindow(qtw.QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle("Hello World!")
# Set Vertical Layout
self.setLayout(qtw.QVBoxLayout())
# Label
lab = qtw.QLabel("Whats Your Name?")
lab.setFont(qtg.QFont("Arial", 20))
self.layout().addWidget(lab)
# Text Box
textB = qtw.QTextEdit(
lineWrapMode=qtw.QTextEdit.FixedColumnWidth,
lineWrapColumnOrWidth=25,
placeholderText="Hello World!",
# html="<h1> the html </h1>"
# plainText="The Real Text Value"
# readOnly=True, # default False
# acceptRichText=True # able to bring formatting
)
textB.setFont(qtg.QFont("Arial", 14))
self.layout().addWidget(textB)
def submit():
lab.setText(f"Value= {textB.toPlainText()}")
# textB.setText("")
textB.setPlainText("") # both are same in this case
# Create a Button
btn = qtw.QPushButton("Submit", clicked=submit)
self.layout().addWidget(btn)
self.show()
app = qtw.QApplication([])
mw = MainWindow()
sys.exit(app.exec_())