본문 바로가기

좋아하는 것_매직IT/96.IT 핫이슈

Textual - 파이썬용 TUI 프레임워크 (github.com/Textualize)

반응형

Textual - 파이썬용 TUI 프레임워크를 소개합니다.

깃허브에서는 Textual를 아래와 같이 소개하고 있고요..
Textual is a TUI (Text User Interface) framework for Python inspired by modern web development. Currently a Work in Progress.

한마디로 Textual 를 정의하자면, 파이썬용 TUI 프레임워크 라고 머릿속에 넣어두시면 될것 같습니다.

호환성관련해서 알아보니..MacOS / 리눅스 /윈도우 모두 지원하네요~

Compatibility

Textual currently runs on MacOS / Linux / Windows.

설치는 아래와 같이 진행하시면 되고요..

Installation

You can install Textual via pip (pip install textual), or by checking out the repo and installing with poetry.

poetry install

Once installed you can run the following command for a quick test, or see examples (below):

python -m textual.app
 

Textual requires Python 3.7 or above.

예제또한 아래와 같이 보여주고 있네요..

아래는 위젯을 만드시 예제 소스고요..

Creating Widgets

You can create your own widgets by subclassing the textual.widget.Widget class and implementing a render() method which should return anything that can be rendered with Rich, including a plain string which will be interpreted as console markup.

Let's look at an example with a custom widget:

from rich.panel import Panel

from textual.app import App
from textual.reactive import Reactive
from textual.widget import Widget


class Hover(Widget):

    mouse_over = Reactive(False)

    def render(self) -> Panel:
        return Panel("Hello [b]World[/b]", style=("on red" if self.mouse_over else ""))

    def on_enter(self) -> None:
        self.mouse_over = True

    def on_leave(self) -> None:
        self.mouse_over = False


class HoverApp(App):
    """Demonstrates custom widgets"""

    async def on_mount(self) -> None:
        hovers = (Hover() for _ in range(10))
        await self.view.dock(*hovers, edge="top")


HoverApp.run(log="textual.log")

 

Textual 의 특징을 간단하게 정리하면 아래와 같습니다.

  • 최신 웹 개발 방식을 이용한 TUI(Text User Interface) 프레임워크
    → Curses 같은 방식이 아닌 CSS 와 Vue/React 등의 기술등을 이용
  • 비동기 이벤트 핸들링(async/await 사용)
  • Rich 라이브러리를 사용하여 모든 렌더링 기능을 그대로 이용 가능
  • 맥/윈/리눅스 지원

좀 더 자세한 내용은 아래 깃허브를 방문하시면 좋을것 같네요..

오늘 블로그는 여기까지고요..
항상 믿고 봐주셔서 감사합니다.

728x90
300x250