英文:
Visual Elements not updating in real time with Taipy GUI
问题
对不起,我不会为您翻译代码。
英文:
Is it normal that when I attempt to add a value to my list or change my data using a button, I do not observe any modifications on the GUI?
Despite this, after refreshing the page, the accurate list is displayed.
from taipy.gui import Gui
import pandas as pd
a_list = [1,2,3]
data = pd.DataFrame({"x":[1,2,3], "y":[2,1,3]})
md = """
<|Update|button|on_action=update|>
# My list
<|{a_list}|>
# My data
<|{data}|table|width=fit-content|>
"""
def update(state):
state.a_list.append(4)
state.data["y"] = [10, 4, 3]
Gui(md).run()
For example, in the code above, clicking the button should add 4 to my list and change my table. However, I see no modification in real time. When I refresh my page, I see the right modifications.
After clicking and before refreshing:
<img src="https://i.stack.imgur.com/RkKko.png" width="300" height="300">
After refreshing:
<img src="https://i.stack.imgur.com/AZwtc.png" width="300" height="300">
答案1
得分: 1
Taipy在这一组特定赋值(.append()
,.drop()
)中不直接更改您的GUI。要实时看到更改,您必须使用普通的“等于”赋值(state.xxx = yyy
)。您的代码将如下所示:
from taipy.gui import Gui
import pandas as pd
a_list = [1,2,3]
data = pd.DataFrame({"x":[1,2,3], "y":[2,1,3]})
md = """
<|Update|button|on_action=update|>
# My list
<|{a_list}|>
# My data
<|{data}|table|width=fit-content|>
"""
def update(state):
state.a_list += [4]
temp = state.data
temp["y"] = [10, 4, 3]
state.data = temp
Gui(md).run()
请注意,这是一段Python代码示例,包括Taipy的GUI元素和一个用于更新GUI的函数。
英文:
Taipy does not directly change your GUI with this set of specific assignments (.append()
, .drop()
). You must use a regular ‘equals’ assignment to see changes in real time (state.xxx = yyy
). Your code will look like this:
from taipy.gui import Gui
import pandas as pd
a_list = [1,2,3]
data = pd.DataFrame({"x":[1,2,3], "y":[2,1,3]})
md = """
<|Update|button|on_action=update|>
# My list
<|{a_list}|>
# My data
<|{data}|table|width=fit-content|>
"""
def update(state):
state.a_list += [4]
temp = state.data
temp["y"] = [10, 4, 3]
state.data = temp
Gui(md).run()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论