[Python] NiceGui log scrollbar doesn't stick to bottom if too fast

Discussão em 'Python' iniciado por Stack, Maio 8, 2025.

  1. Stack

    Stack Membro Participativo

    The following code is my log created along with an attached log handler, which uses a queue to control the pace at which the log gets written to.

    When my logging gets too fast, the scrollbar no longer sticks to the bottom (as if it falls behind and loses grip), and you have to manually scroll down.

    When the queue gets written to faster than the current timer setting allows, the log will end up being throttled in order to keep the scrolling attached to the bottom.

    BUT, when I tested changing the timer value to 0.015 or less, the scrolling will not stay at the bottom, and it gets left behind. After that, any new logging will continue adding but you won't see it on the GUI as it's no longer visible.

    I found posts regarding the opposite - not jumping to the bottom when new log is added - but nothing regarding staying at the bottom when the logging is too fast.

    with ui.column().classes("w-3/4 h-full"):
    ui.label("Output")
    log = ui.log(max_lines=1000).classes("w-full flex-grow").style(
    "height: 50vh;"
    )
    handler = LogElementHandler(log)
    logger.addHandler(handler)
    ui.context.client.on_disconnect(lambda: logger.removeHandler(handler))
    ui.label("Error Log")
    errorlog = ui.log(max_lines=1000).classes("w-full flex-grow").style(
    "height: 20vh"
    )

    # Update the log on the main process
    ui.timer(0.02, callback=lambda: logger.warning(queue.get()) if not queue.empty() else None)

    Continue reading...

Compartilhe esta Página