Skip to content
Discussion options

You must be logged in to vote

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}')

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by DeCabMax
Comment options

You must be logged in to vote
2 replies
@rohitsathish
Comment options

@falkoschindler
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants