如何使用Python Textual框架获取多行输入

huangapple go评论99阅读模式
英文:

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 one 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()
英文:

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

答案1

得分: 1

查看新的文本 TextArea 小部件。

英文:

See the new Textual TextArea widget.

huangapple
  • 本文由 发表于 2023年5月28日 05:02:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76349029.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定