Why does set_text not work? #268
Replies: 2 comments 8 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks @falkoschindler for the prompt response. I amended the code as further below. I have a follow-up question. Even though I am able to assign the value (e.value of the ui.tree) to the variable (wch_calc) in the function set_wch_calc, its value is not retained in wch_calc even after ui.update. The statement (after the ui.tree statement) ui.label(f"wch_calc: {wch_calc}") has no value. from nicegui import ui
wch_calc = ''
def set_wch_calc(vval):
global wch_calc
wch_calc = vval
ui.update
def DisplayCalcOverview():
global wch_calc
return f"<h1>You chose {wch_calc.upper()}</h1>"
@ui.page('/main_page')
def main_page():
global wch_calc
with ui.left_drawer(top_corner=False, bottom_corner=False).style('background-color: #F8EDE3').props('width=260 bordered'):
with ui.row():
with ui.column():
with ui.row():
ui.html("<p style='font-size: 24px;'>Calculators:</p>")
ui.tree([
{'id': 'Drug Dose', 'children': [{'id': 'BSA'}]},
{'id': 'Oncology', 'children': [{'id': 'Recist S'}, {'id': 'Recist M'}, {'id': 'Recist A'}]},
{'id': 'Gastroenterology', 'children': [{'id': 'Mayo Score'}, {'id': 'Harvey Bradshaw'}, {'id': 'SCCAI'}, {'id': 'SESCD'}]},
], label_key='id', on_select=lambda e: set_wch_calc(e.value))
ui.label(f"wch_calc: {wch_calc}")
if wch_calc == '':
ui.label('No Calc chosen')
else:
htmlstr = DisplayCalcOverview(wch_calc)
ui.html(htmlstr)
ui.button("Click for Main Page", on_click=lambda: ui.open('main_page'))
ui.run() |
Beta Was this translation helpful? Give feedback.
-
In the code below, why is it not possible to set the value of the
wch_calc
variable to thee.value
of theui.tree
widget withon_select=lambda e: wch_calc.set_text(e.value)
?Because
wch_calc
cannot be set, it is not being processed by theif wch_calc == ''
statement.Any help is appreciated...
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions