From e10e8b3e33bdb68b12a34c1f9ae693d36e109377 Mon Sep 17 00:00:00 2001 From: aiolishi Date: Wed, 13 Mar 2024 09:47:15 +0800 Subject: [PATCH] shao --- 实例学习 nicegui/add point.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/实例学习 nicegui/add point.py b/实例学习 nicegui/add point.py index d942702..1fd45d5 100644 --- a/实例学习 nicegui/add point.py +++ b/实例学习 nicegui/add point.py @@ -1,5 +1,6 @@ import plotly.graph_objects as go from nicegui import ui +import pandas as pd from random import random @@ -21,7 +22,17 @@ def add_trace(): ui.button('Add trace', on_click=add_trace) +df = pd.DataFrame(columns=['x', 'y', 'z']) +table = ui.table.from_pandas(df).classes('max-h-40') +def add_to_dataframe(): + # 将新行添加到DataFrame + new_row = {'x': x.value, 'y': y.value, 'z': z.value} + global df # 使用global声明,以便在函数内部修改全局变量df + df = df.append(new_row, ignore_index=True) + # 更新表格显示 + + table = ui.table.from_pandas(df).classes('max-h-40') - +ui.button('Add to DataFrame', on_click=add_to_dataframe) ui.run() \ No newline at end of file