TextInput: value not available without pressing Enter?

I have a GUI where a TextInput widget is a part and a button. The idea is that when the button is pressed, all the current inputs and selections are used to process something.

The problem is: when the code is run after the button is pressed, the TextInput value is not what is actually in the widget! Instead empty or previous value is returned!

On closer inspection, this seems to be a timing/locking problem: when the code is invoked from the button press event, the value of the TextInput is not available.
However when the “Enter” key is hit after entering the text and before pressing the button, the value always is available correctly.

Hir is some code to test this out:

import panel as pn

ws = {}
w_text = pn.widgets.TextInput(name='TextInput')
ws["text"] = w_text
w_button = pn.widgets.Button(name='Press')
ws["button"] = w_button

def on_button(event):
    print(f"Text value: >>{ws['text'].value}<<")


show = pn.Column(
    w_text, w_button


server = show.show(port=8080)

When the gui is shown try this to reproduce the problem:

  • start the program in a terminal that remains visible when viewing the GUI in the browser
  • run the program and look at the GUI in the browser
  • enter something in the text input field
  • QUICKLY after entering click the button with the mouse
  • the print statement will output an empty string, not what you just entered into the text input!

If you instead let some time pass after entering the text or press Enter there before clicking the button, the correct value is shown.

Is there a way to make sure that the correct current value is fetched of what is present in the widget when the button is clicked?

I am using panel version 1.2.3 with Python 3.8.17 and the GUI is running on Firefox 125.0.3

Try to use value_input instead of value


Oh, I should have RTFM :confused:
Yes, indeed, that works, thanks!

1 Like