Toggle dark mode

Hi,

🎉 V2.0 is out. 

Check out our new release!

M
October 27, 2022

Change value in a list

Welcome to Taipy Forums Using Taipy Change value in a list

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #236843
    DataTesterDataTester
    Participant

    I am trying to add a value (4) to my list through a button, but I don’t see any change on the GUI. However, I see that my list is updated in the Python console and if I refresh the page, I see the correct list displayed. Is it normal?

    from taipy import Gui

    list_a = [1,2,3]

    md = “””
    <|Add value|button|on_action=add_value|>

    <|{list_a}|>
    “””

    def add_value(state):
    print(“Before”, state.list_a)
    state.list_a.append(4)
    print(“After”, state.list_a)

    Gui(md).run()

    Thank you in advance

    #236844
    Florian JactaFlorian Jacta
    Keymaster

    Hi,
    Taipy doesn’t support this kind of assignment, you should use an ‘equals’ assignment to see changes in real-time. This principle is also used for other elements such as Pandas DataFrame or dictionaries. Your code will look like this:

    from taipy import Gui

    list_a = [1,2,3]

    md = “””
    <|Add value|button|on_action=add_value|>

    <|{list_a}|>
    “””

    def add_value(state):
    print(“Before”, state.list_a)
    state.list_a += [4]
    print(“After”, state.list_a)

    Gui(md).run()

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.