Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ipywidgets return press in text box not working #6555

Open
teddyrendahl opened this issue Jun 12, 2019 · 5 comments
Open

ipywidgets return press in text box not working #6555

teddyrendahl opened this issue Jun 12, 2019 · 5 comments
Labels
Milestone

Comments

@teddyrendahl
Copy link

Describe the bug
I have a FloatTextBox from ipywidgets linked to a separate FloatTextBox. When I press "Enter" inside the text box, nothing happens until I change the focus in my browser. Pressing the incremental change button works instantly. When running in a stand alone Jupyter Notebook the enter propagates the change immediately.

To Reproduce
Steps to reproduce the behavior:

from ipywidgets import interact
import ipywidgets as widgets
from IPython.display import display

read_widget = widgets.FloatText(value=0, disabled=True) 
write_widget = widgets.FloatText(value=0)

def put(change):
    read_widget.value = change['new']

write_widget.observe(put, names='value')
layout = widgets.HBox([read_widget, write_widget])
display(layout)

Expected behavior
Pressing "Enter" in the writable text box causes the read-only text box to change instantly.

Screenshots
jupyter

Desktop (please complete the following information):

  • OS: MacOS 10.12.6
  • Browser: Chrome 74
Environment
appnope                   0.1.0                 py37_1000    conda-forge
attrs                     19.1.0                     py_0    conda-forge
backcall                  0.1.0                      py_0    conda-forge
bleach                    3.1.0                      py_0    conda-forge
ca-certificates           2019.3.9             hecc5488_0    conda-forge
certifi                   2019.3.9                 py37_0    conda-forge
dbus                      1.13.6               h2f22bb5_0    conda-forge
decorator                 4.4.0                      py_0    conda-forge
defusedxml                0.5.0                      py_1    conda-forge
entrypoints               0.3                   py37_1000    conda-forge
expat                     2.2.5             h0a44026_1002    conda-forge
gettext                   0.19.8.1          h46ab8bc_1002    conda-forge
glib                      2.58.3            h2836805_1001    conda-forge
icu                       58.2              h0a44026_1000    conda-forge
ipykernel                 5.1.1            py37h24bf2e0_0    conda-forge
ipython                   7.5.0            py37h24bf2e0_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.4.2                      py_0    conda-forge
jedi                      0.13.3                   py37_0    conda-forge
jinja2                    2.10.1                     py_0    conda-forge
jpeg                      9c                h1de35cc_1001    conda-forge
jsonschema                3.0.1                    py37_0    conda-forge
jupyter                   1.0.0                      py_2    conda-forge
jupyter_client            5.2.4                      py_3    conda-forge
jupyter_console           6.0.0                      py_0    conda-forge
jupyter_core              4.4.0                      py_0    conda-forge
jupyter_server            0.0.5                    py37_0    conda-forge
jupyterlab                0.35.6                   py37_0    conda-forge
jupyterlab_pygments       0.1.0                      py_0    conda-forge
jupyterlab_server         0.2.0                      py_0    conda-forge
libblas                   3.8.0                7_openblas    conda-forge
libcblas                  3.8.0                7_openblas    conda-forge
libcxx                    4.0.1                hcfea43d_1  
libcxxabi                 4.0.1                hcfea43d_1  
libedit                   3.1.20181209         hb402a30_0  
libffi                    3.2.1                h475c297_4  
libgfortran               3.0.1                         0    conda-forge
libiconv                  1.15              h01d97ff_1005    conda-forge
liblapack                 3.8.0                7_openblas    conda-forge
libpng                    1.6.37               h2573ce8_0    conda-forge
libsodium                 1.0.16            h1de35cc_1001    conda-forge
markupsafe                1.1.1            py37h1de35cc_0    conda-forge
mistune                   0.8.4           py37h1de35cc_1000    conda-forge
nbconvert                 5.5.0                      py_0    conda-forge
nbformat                  4.4.0                      py_1    conda-forge
ncurses                   6.1                  h0a44026_1  
networkx                  2.3                        py_0    conda-forge
nodejs                    11.14.0              h6de7cb9_1    conda-forge
notebook                  5.7.8                    py37_1    conda-forge
numpy                     1.16.4           py37h6b0580a_0    conda-forge
openblas                  0.3.5             h436c29b_1001    conda-forge
openssl                   1.1.1b               h01d97ff_2    conda-forge
ophyd                     1.3.3                    py37_0    conda-forge
pandoc                    2.7.2                         0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parso                     0.4.0                      py_0    conda-forge
pcre                      8.41              h0a44026_1003    conda-forge
pexpect                   4.7.0                    py37_0    conda-forge
pickleshare               0.7.5                 py37_1000    conda-forge
pip                       19.1.1                   py37_0  
prometheus_client         0.7.0                      py_0    conda-forge
prompt_toolkit            2.0.9                      py_0    conda-forge
ptyprocess                0.6.0                   py_1001    conda-forge
pygments                  2.4.2                      py_0    conda-forge
pyqt                      5.9.2            py37h2a560b1_0    conda-forge
pyrsistent                0.15.2           py37h01d97ff_0    conda-forge
python                    3.7.3                h359304d_0  
python-dateutil           2.8.0                      py_0    conda-forge
pyzmq                     18.0.1           py37h2d07e9b_1    conda-forge
qt                        5.9.7                h93ee506_2    conda-forge
qtconsole                 4.5.1                      py_0    conda-forge
readline                  7.0                  h1de35cc_5  
send2trash                1.5.0                      py_0    conda-forge
setuptools                41.0.1                   py37_0  
sip                       4.19.8          py37h0a44026_1000    conda-forge
six                       1.12.0                py37_1000    conda-forge
sqlite                    3.28.0               ha441bb4_0  
terminado                 0.8.2                    py37_0    conda-forge
testpath                  0.4.2                   py_1001    conda-forge
tk                        8.6.8                ha441bb4_0  
tornado                   6.0.2            py37h01d97ff_0    conda-forge
traitlets                 4.3.2                 py37_1000    conda-forge
voila                     0.1.2                      py_0    conda-forge
wcwidth                   0.1.7                      py_1    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.33.4                   py37_0  
widgetsnbextension        3.4.2                 py37_1000    conda-forge
xz                        5.2.4                h1de35cc_4  
zeromq                    4.3.1             h0a44026_1000    conda-forge
zlib                      1.2.11               h1de35cc_3  
@saulshanabrook saulshanabrook added this to the Future milestone Jun 17, 2019
@tfmark
Copy link

tfmark commented Jul 8, 2021

Is there a workaround for this? I'd like to capture when Enter is pressed in a Text widget, but it appears to do nothing?

import ipywidgets as widgets
caption = widgets.Output()

def onchange(change):
    with caption:
        print(change)

text = widgets.Text()
text.observe(onchange)

display(caption, text)

EDIT:
Using the on_submit handler does the job:

text.on_submit(onchange)

@DiegoF90
Copy link

@tfmark very helpful thanks. Did you find a workaround for the FloatTextBox class?
This and BoundedIntText (in my case) do not seem to have the "on_submit" option.

@tfmark
Copy link

tfmark commented Jul 16, 2021

I cannot reproduce your behaviour with 7.6.3 are you still running 7.4.x ?

import ipywidgets as widgets
read_widget = widgets.FloatText(value=0, disabled=True)
write_widget = widgets.FloatText(value=0)

def put(change):
    read_widget.value = change["new"]
    
write_widget.observe(put, names='value')

layout = widgets.HBox([read_widget, write_widget])
display(layout)

the read_widget value updates when I hit Enter inside the write_widget

@DiegoF90
Copy link

I see... I might just need to update then. I am using 7.5.1.

@aimfeld
Copy link

aimfeld commented Nov 8, 2021

I have exactly the same problem with the IntText input (ipywidgets 7.6.5). When I press enter, nothing happens, but using the up/down arrows or changing focus does work.

This is how I configure it:

token_id_input = IntText(description='Token ID:', disabled=False, continuous_update=False)
token_id_input.observe(show_asset_info, names="value")

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

No branches or pull requests

5 participants