1

I have a ttk.Enter widget that I want the user to enter a time, but I only want the user to be able to enter the time in the format "HH:MM AM/PM" ie. 1;30 PM, 8:00 AM, etc

Then I will enter the info into a MySQL database as 1:30 PM = 13:30 using list striping to remove the AM/PM and add 12 hours where approprate.

The main question is how to control the input format?

Thanks, John

  • you can use `bind("KeyRelease", function)` to check value in Entry after every pressed key and somehow check if it still match to pattern. Eventually you can assign `StringVar` to `Entry` and use `trace()` to execute function when `StringVar` changes value and then somehow check if it still match to pattern. – furas Aug 03 '20 at 16:32
  • [Entry](https://effbot.org/tkinterbook/entry.htm) has also `validate=` and `validatecommand=` to assing function which can check if value match pattern. – furas Aug 03 '20 at 16:39
  • [Interactively validating Entry widget content in tkinter](https://stackoverflow.com/questions/4140437/interactively-validating-entry-widget-content-in-tkinter) – furas Aug 03 '20 at 19:29

0 Answers0