英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论