You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @Poleg44. You have many tools for controlling the values of inputs. In this case, you can use a combination of maxchar, input_type, and an on_change callback.
Maxchar limits the user to enter numbers greater than 99. Input type restricts input chars only to numeric, and on_change validates the time and responds appropriately. See the following example:
importpygame_menufrompygame_menu.examplesimportcreate_example_windowfrompygame_menu.localsimportINPUT_INTsurface=create_example_window('Time validator', (600, 400))
# Create the menumenu=pygame_menu.Menu(height=300, theme=pygame_menu.themes.THEME_DARK, title='Test timer', width=400)
# Add the input time entry and validatetime_input=menu.add.text_input('Time: ', input_type=INPUT_INT, maxchar=2)
defvalidate_time(value, *args):
ifvalue<0:
time_input.set_value(0)
elifvalue>59:
time_input.set_value(59)
time_input.set_onchange(validate_time)
menu.add.button('Quit', pygame_menu.events.EXIT)
menu.mainloop(surface)
In the example, the time is validated; if less than 0, set 0; if greater than 59, set 59. There are better solutions, like building your own Widget based on TextInput. But I guess this works, and it is quite simple.
I do time widget with text_input for sec. How can i use onchange event for control sec value <=59?
I need example with onchange event using.
The text was updated successfully, but these errors were encountered: