PyQt Multiline Text Input Box

14,401

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()
Share:
14,401
Ajax1234
Author by

Ajax1234

I am currently a student and a Python programming enthusiast. My main computer science interests include data mining, compiler design, algorithms, web application development, and peer-to-peer technologies.

Updated on June 13, 2022

Comments

  • Ajax1234
    Ajax1234 about 2 years

    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()