taipy

Taipy toggle works with markdown syntax but not python


Trying to implement a toggle control on my page. Seems to work when using markdown but not when using python.

Using taipy-gui 3.1.2

This works as expected

from taipy.gui import Gui

def on_toggle(state):
    print("toggled")

value = False

page = """
<|{value}|toggle|on_change=on_toggle|>
"""

if __name__ == "__main__":
    Gui(page).run(debug=True)

This will show the toggle but the toggle does nothing

from taipy.gui import Gui
import taipy.gui.builder as tgb

def on_toggle(state):
    print("toggled")

value = False

with tgb.Page() as page:
    tgb.toggle("{value}", on_change=on_toggle)


if __name__ == "__main__":
    Gui(page).run(debug=True)

Am I doing something wrong with the python version?


Solution

  • Alex from Taipy here. This is definitely a bug. I'll create an issue on our repo. You can work around it by forcing the value assignment like so:

    tgb.toggle(value="{value}", on_change=on_toggle)