Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Wait for a button widget to be clicked #3145

Open
lodm94 opened this issue Mar 3, 2021 · 2 comments
Open

Wait for a button widget to be clicked #3145

lodm94 opened this issue Mar 3, 2021 · 2 comments

Comments

@lodm94
Copy link

lodm94 commented Mar 3, 2021

HI all,
i am struggling with the following problem. I can't find a solution reading the documentation so i am asking here.
Let's assume i want to deploy a feedback stage for a certain application.
Let's assume i have a text-box for output and two button for input like the following:

import ipywidgets as ipw
from ipywidgets import Layout
txt_out=ipw.Textarea(
        value='are you interested in leaving a feedback?',
        disabled=True,
        layout=Layout(border='solid 1px', width = '650px', height = '150px', )
    )

yes=ipw.Button(
        description='',
        disabled=False,
        button_style='info', # 'success', 'info', 'warning', 'danger' or ''
        tooltip='Yes',
        icon='thumbs-up',
        layout=Layout(height='50px')
    )

no=ipw.Button(
        description='',
        disabled=False,
        button_style='info', # 'success', 'info', 'warning', 'danger' or ''
        tooltip='No',
        icon='thumbs-down',
        layout=Layout(height='50px'))

box1=ipw.HBox([yes,no])
box2=ipw.VBox([txt_out,box1])
display(box2)

Wich results like:

image

How can i wait for the user press a button inside a function? I would use thread, but exactly wich function should i thread? I cant thread directly the on_click button function, am i right?

The goal is change txt_out.value according to user choice (multiple times, indeed).
Appreciate your help

Thanks

@msat59
Copy link

msat59 commented Dec 30, 2021

Have you solved it?
It's my question too.

@FishingBehindTheNet
Copy link

to regester input form a text box u can use txt_out.observe(function, names="value") this checks if the user pressed enter. If u need to have them press the button u can use yes.on_click(function). If u need to make sure the user gave an input before pressing yes, use the following: yes.on_click(lambda PlaceHolder: function(PlaceHolder) if txt_out.value else None)

This makes sure that there is a input before activating the function. you could also use the txt_out.value in your function to give feadback or a errormessage

I hope this awnsers your question!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants