I am working with PyQt and am attempting to build a multiline text input box for users. However, when I run the code below, I get a box that only allows for a single line of text to be entered. How to I fix it so that the user can enter as many lines as necessary?
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
def window():
app = QApplication(sys.argv)
w = QWidget()
w.resize(640, 480)
textBox = QLineEdit(w)
textBox.move(250, 120)
button = QPushButton("click me")
button.move(20, 80)
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
window()
To create a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. It is used within a form, to allow users to input text over multiple rows.
Definition and Usage. The <textarea> tag defines a multi-line text input control. The <textarea> element is often used in a form, to collect user inputs like comments or reviews.
To break the text up in your HTML Input Buttons all you have to do is tap the enter key and make sure the line of code is broken into several lines.
The Multiline Text Field can be used to store larger amounts of text. The Multiline Text Field offers a lot of formatting options, such as: Adding bulleted and numbered lists. Use bold, italics and underline styling. Change the text format and size.
QLineEdit
is a widget that provides a single line, not multiline. You can use QPlainTextEdit
for that purpose.
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
def window():
app = QApplication(sys.argv)
w = QWidget()
w.resize(640, 480)
textBox = QPlainTextEdit(w)
textBox.move(250, 120)
button = QPushButton("click me", w)
button.move(20, 80)
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
window()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With