Skip to content

Recommendation on passing input values in #76

Closed Answered by falkoschindler
4l1fe asked this question in Q&A
Discussion options

You must be logged in to vote

Well, my recommendation depends. The most trivial way would be to pass all values:

def handle_inputs(a, b, c):
    print(a, b, c)

a = ui.input()
b = ui.input()
c = ui.input()
ui.button(on_click=lambda: handle_inputs(a.value, b.value, c.value))

If the list of inputs gets too long, you could access the UI elements directly:

def handle_more_inputs():
    print(d.value, e.value, f.value)

d = ui.input()
e = ui.input()
f = ui.input()
ui.button(on_click=handle_more_inputs)

But maybe it's better to pack all data into a model class:

@dataclass
class Model:
    g: str = ''
    h: str = ''
    i: str = ''

def handle_model(model):
    print(model.g, model.h, model.i)

model = Model()
ui.input().bi…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@4l1fe
Comment options

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