pyimgui / pyimgui

Cython-based Python bindings for dear imgui
https://pyimgui.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.34k stars 180 forks source link

input_text resets after losing focus #347

Open Hirikava opened 1 year ago

Hirikava commented 1 year ago

I tried this simple example of input_text with pyimgui + GLFW. It works fine untill text bar losing focus and value of input resets to default one. text_val = 'Please, type the coefficient here.' imgui.begin("Example: text input") changed, text_val = imgui.input_text('Coefficient:', text_val) imgui.text('You wrote:') imgui.same_line() imgui.text(text_val) imgui.end()

Aman-Anas commented 1 year ago

Remember, this runs every frame - so when you define text_val on line 1, you're actually re-defining it every frame. You should only set text_val once, since after that it needs to hold whatever value the user inputs.

Alternatively, you can use input_text_with_hint to show a hint like that easily