1

I would like to be able to click on a row and show a specific image depending on the row.

from taipy.gui import Gui

data = {"fruits":['apple', 'banana', 'apple', 'orange', 'banana', 'mango'],
        "width":[12, 12, 31, 4, 8, 6],}

md = """
<|{data}|table|>
"""

Gui(md).run()
Areth
  • 185
  • 5

1 Answers1

1

The on_action can be put on the table visual element. The index of the table can be extracted to show what you want.

In the code below, I click on a row. The fruit on which I clicked will be displayed and a notification will be created.

from taipy.gui import Gui, notify

data = {"fruits":['apple', 'banana', 'apple', 'orange', 'banana', 'mango'],
        "width":[12, 12, 31, 4, 8, 6],}

fruits_to_display = ''

md = """
<|{data}|table|on_action=do_something|>

<|{fruits_to_display}|>
"""

def do_something(state, var_name, action, payload):
    idx = payload["index"]
    state.fruits_to_display = data["fruits"][idx]
    notify(state, "success", f'Clicked on fruit: {data["fruits"][idx]}')    

Gui(md).run()

Table with fruits

Florian Jacta
  • 1,143
  • 1
  • 2
  • 5