-
QuestionHi, def function(x,y):
return_v1 = np.sqrt(x**2 + y**2 )
return return_v1
x = ui.number(label='x',format='%.4f', value = 0)
y = ui.number(label='x',format='%.4f', value = 0)
z = ui.button(on_click= lambda e:function_1(x.value,y.value))
ui.label( )
## A
## |
## here i want to show the return value |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Straying a bit further away from your code, I would do it with bindings: @dataclass
class Coordinate:
x: float
y: float
@property
def z(self) -> float:
return np.sqrt((self.x or 0)**2 + (self.y or 0)**2)
c = Coordinate(0, 0)
ui.number(label='x', format='%.4f').bind_value(c, 'x')
ui.number(label='y', format='%.4f').bind_value(c, 'y')
ui.label().bind_text_from(c, 'z', backward=lambda z: f'z={z:.4f}') |
Beta Was this translation helpful? Give feedback.
-
|
Regarding the original question: Note that when To update the label, you can use binding like in @rodja's answer. Or you let the event handler update the label: def function_1(x: float, y: float):
z.text = f'{np.sqrt(x**2 + y**2):.4f}'
x = ui.number(label='x', format='%.4f', value=0)
y = ui.number(label='y', format='%.4f', value=0)
ui.button('Compute', on_click=lambda: function_1(x.value, y.value))
z = ui.label() |
Beta Was this translation helpful? Give feedback.
Straying a bit further away from your code, I would do it with bindings: