How can I add a if else in a label?

Hi,

I’m using psutil to see if a program is opened or not, and I whant to use that to hide or see a TAB.

This is how the tab looks like:

dbc.Tab(label="River Bluff",tab_id="graph14",style={
    "color":"#f0f8ff",
    "background-color": "#000000"
}, active_label_style={"color":"#f0f8ff","background-color": "#000000"},children=[
    
                    dbc.Container(
                    [
                        html.H1("River Bluff EV"),
                        html.Hr(),
                        dbc.Row(
                            [
                                dbc.Col(controls017 , md=4),
                                dbc.Col([
                                    html.H5("EV ($)"),
                                    html.Div(id='contenedor-evr', style={'whiteSpace': 'pre-line'})
                                ],md=8)
                            ],
                            align="center",
                        ),
                        html.Hr(),
                        dbc.Row([
                                html.P(""),
                                html.P(""),
                                html.P(""),
                                html.P(""),
                                html.P(""),
                                html.P(""),
                            ]),
                    ],
                    fluid=True,
                    )]),

and this are the conditions for psutil

import psutil

def programa_esta_abierto(nombre_programa):
    for proceso in psutil.process_iter(['pid', 'name']):
        if nombre_programa.lower() in proceso.info['name'].lower():
            return True
    return False

# Ejemplo de uso
nombre_programa = 'PokerStars.exe'  # Reemplaza con el nombre del programa que deseas verificar
if programa_esta_abierto(nombre_programa):
    print(f"El programa {nombre_programa} está abierto.")
else:
    print(f"El programa {nombre_programa} no está abierto.")

How can I hade the tab when the program is opened?

Hey,
I think you could set the style of your tab like this:

style={
    "color":"#f0f8ff",
    "background-color": "#000000"
 "opacity": 1 if programa_esta_abierto(nombre_programa) else 0
}

Thanks! I cant try it now … but should work

1 Like

Hi, it doesnt work … any other way to hide the tabs?

ok, I found a way arround this … Im doing an if condition with the navigation tabs …

how can I check this condition every time the app refreshes (updata)?

What I mean with this is that, If I start the app with the other software opened, the tab hides, but I could start the app without the other software and after that open the software and pass arround this … how can I make it work propperly (when the software is running the app hides tabs)?

I opened a similar one … please check it

link

1 Like