Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt Multiline Text Input Box

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()
like image 733
Ajax1234 Avatar asked Feb 15 '17 01:02

Ajax1234


People also ask

How do you input text into multiline?

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.

How can we enter data in more than one line in an HTML form?

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.

How do you break a line into input?

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.

What is a multiline text?

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.


1 Answers

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()
like image 87
eyllanesc Avatar answered Sep 20 '22 21:09

eyllanesc