Tdqm text color change

Hi @kazux68k

I can see your use case has not been anticipated or there is a bug in the Panel code.

The lines of code marked changes your color

You can fix it using the code below.

import time

import panel as pn

# **** Hack Fix ****

class ptqdm2(pn.widgets.indicators.ptqdm):
    def display(self, msg=None, pos=None, bar_style=None):
        super().display(msg, pos)
        style = self._indicator.text_pane.style or {}
        if not "color" in style:
            color = self.colour or 'black'
            self._indicator.text_pane.style = dict(style, color=color)
        if self.total is not None and self.n is not None:
            self._indicator.max = int(self.total) # Can be numpy.int64
            self._indicator.value = int(self.n)
            self._indicator.text = self._to_text(**self.format_dict)
        return True
pn.widgets.indicators.ptqdm=ptqdm2

# **** Hack Fix ****

from panel.widgets import Tqdm

pn.extension()

tqdm_outer = Tqdm()
tqdm_inner = Tqdm(margin=(0, 0, 0, 20))
tqdm_outer.text_pane.style={'color': 'green'}
tqdm_inner.text_pane.style={'color': 'red'}

def run_nested_loop(*events, timeout=0.05):
    for i in tqdm_outer(range(10)):
        for j in tqdm_inner(range(10)):
            time.sleep(timeout)
            
run_nested_loop(timeout=0.001)

button = pn.widgets.Button(name="Run Nested Loop", button_type="success")
button.on_click(run_nested_loop)

app = pn.Column(tqdm_outer, tqdm_inner,button)

app.servable()
1 Like