pythontuitextual

How to get a multiline input with python Textual framework


I'm using the Textual-framework in Python and I want the user to enter a multiline Text. However, I cannot find a widget that does the trick.

With the Input widget on can only enter one line. I tried to tweak it, but I cannot fix it so it wraps the text, when it overflows. Here is a minimal example. I also tried the overflow style, but it doesn't work.

from textual.app import App
from textual.binding import Binding
from textual.widgets import Input


class MultiLineInput(Input):
    BINDINGS = [Binding("enter", "newline", "New line", show=True)]

    def action_newline(self):
        self.value += "\n"
        self.cursor_position = len(self.value)

    def on_mount(self):
        self.styles.height="4"


class Minimal(App):
    def compose(self):
        yield MultiLineInput(id="input")


if __name__ == "__main__":
    app = Minimal()
    app.run()


Solution

  • See the new Textual TextArea widget.