Skip to content

Question: gradual transition from standard command line application with prints() to textual app #3505

Answered by davep
menteora asked this question in Q&A
Discussion options

You must be logged in to vote

You can use print capturing and direct the output to your app, a screen or a specific widget. For example:

from textual.app import App, ComposeResult
from textual.events import Print
from textual.widgets import Log

class PrintingApp(App[None]):

    def compose(self) -> ComposeResult:
        yield Log()

    def on_print(self, event: Print) -> None:
        self.query_one(Log).write(event.text)

    def on_mount(self) -> None:
        self.begin_capture_print(self)
        print("Your message here")
        print("Your message here 2")

if __name__ == "__main__":
    PrintingApp().run()

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
3 replies
@menteora
Comment options

@davep
Comment options

@menteora
Comment options

Answer selected by menteora
Comment options

You must be logged in to vote
5 replies
@davep
Comment options

@menteora
Comment options

@davep
Comment options

@menteora
Comment options

@menteora
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3502 on October 11, 2023 07:17.