Add a popup dailog in fullscreen app in python prompt_toolkit


I am creating a terminal chat application, where I have a UI with prompt_toolkit.
enter image description here
There In message box i added some commands to perform some action.
To create the Dashboard I used prompt_toolkit.Application And apply my functionalaty on top of this.

class Dashboard(Application):
    """Implemented Dashboard"""

    def __init__(self):
        self.key_bindings = KeyBindings()    
        self.__layout = None

    def create_layout(self):
        """Implemented Dashboard.create_layout"""
        self.__layout = VSplit(
                    [self.__screen_area, self.__message_box]
            ], padding=1, width=2)

    def set_layout(self):
        """Setting the dashboard layout"""
        self.layout = Layout(self.__layout)

    def process_message(self):
        """Implemented send message method"""
        buffer = self.__message_box.buffer
        if buffer:
            if '/' in buffer[0]:
                # INFO: Clear the message box
                buffer = buffer[1:]
                # INFO: Perform the operation
                if buffer in ['clear', 'cls', 'c']:
                elif buffer in ['exit', 'quit', 'q']:
                    # add confirm dailog here
                message = self.__message_box.message

I want to have a pop for confirm dailog like this
enter image description here

And was provided in prompt_toolkit docs

I was trying to add that dailog in py app, but everytime it says Exception This event loop is already running

problem seems like My Dashboard is a loop and i can’t have another loop inside the existing one. I am stuck in this point. Any help or suggestion will be healpfull

Git url to my REPO

Asked By: JRudransh



I think prompt-toolkit is outdated. I have found another python package textual. Using texual you can Build sophisticated TUI with a simple Python API.

Link for GITHUB & PyPI

Example Image

Textual adds interactivity to Rich with an API inspired by modern web development.

On modern terminal software (installed by default on most systems), Textual apps can use 16.7 million colors with mouse support and smooth flicker-free animation. A powerful layout engine and re-usable components makes it possible to build apps that rival the desktop and web experience.

Textual runs on Linux, macOS, and Windows. Textual requires Python 3.7 or above.

Answered By: JRudransh