0

I am new to python and my question is if there is a way to enter data in an entry and when it reaches the indicated number of characters it will automatically jump to the next entry

I need something like this

sample image

Saad
  • 3,340
  • 2
  • 10
  • 32
  • Relevant [Entry validation, to limit the character length](https://stackoverflow.com/a/60904457/7414759). Read up on [Events and Bindings](http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm) and [Tkinter.Widget.bind-method](http://effbot.org/tkinterbook/widget.htm#Tkinter.Widget.bind-method) – stovfl Jun 21 '20 at 07:09
  • You can do with `bind` method also for example: `e1.bind('', lambda _: e2.focus() if len(e1.get()) >= 2 else None)`. But not a advisable way but will work and you can replace `lambda` with a proper function that has more conditions make it more robust. – Saad Jun 21 '20 at 08:45

2 Answers2

0

If the word "automatic" in your question means, "Can a program with the desired behavior be written with Tkinter?" the answer, of course, is yes. See this documentation:

https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/entry.html

especially the information about textvariable, validate, and validatecommand. You may also find this link useful:

https://www.geeksforgeeks.org/tracing-tkinter-variables-in-python/

If the word "automatic" in your question means, "Is there some wonderful function I can call that painlessly provides this functionality in my tkinter program?" I'm pretty sure the answer is no.

Paul Cornelius
  • 9,245
  • 1
  • 15
  • 24
0

if you want to do that I highly suggest using the .trace() method. What this method does in the background --> It calls a function whenever the condition stated is triggered. For example:

name_of_stringvar = StringVar()
Entry(root, textvariable = name_of_stringvar)
name_of_stringvar.trace('w', function_name)

So whenever something is typed into the Entry(), it goes to the function(function_name in this case). You can state the conditions for checking maximum no of characters for the first entry. Then when the limit is being exceeded, use the focus_force() method to move the cursor to the second entry.

Pranav Krishna S
  • 324
  • 2
  • 13