Here is simple Python/Tkinter program with single Entry widget that i want
automatically check is number entered or not.

http://pastebin.com/WkLy2Csb <http://pastebin.com/WkLy2Csb>  

print statement in _validate() function only for debugging. The problem is
in this case visual editing of Entry is incorrect. For example i doing those
steps:

1. Launch program.
2. See '111' value in the Entry
3. Select '111' by left mouse button
4. Press "9" on keyboard
5. Instead of full replace '111' to '9' insert happens and i see '9111'!

Debug log (i numerated steps for convinience):
1. OnValidate: d='-1' i='-1' P='111' s='' S='' v='all' V='forced'
W='.37125736'
2. OnValidate: d='-1' i='-1' P='111' s='111' S='' v='all' V='focusin'
W='.37125736'
3. OnValidate: d='0' i='0' P='' s='111' S='111' v='all' V='key'
W='.37125736'
4. OnValidate: d='1' i='0' *P='9111'* s='111' S='9' v='all' V='key'
W='.37125736'
5. OnValidate: d='0' i='1' P='9' s='9111' S='111' v='all' V='key'
W='.37125736'
6. OnValidate: d='1' i='1' P='99' s='9' S='9' v='all' V='key' W='.37125736'
7. OnValidate: d='1' i='2' P='999' s='99' S='9' v='all' V='key'
W='.37125736'

Pay attention to step 4. It is strange additional step with unwanted Entry
text state ('9111')

But if i change
/return P.isdigit()/
to
/return True/

Everything becomes ok! Entry works like any entry in other programs.

1. OnValidate: d='-1' i='-1' P='111' s='' S='' v='all' V='forced'
W='.37650024'
2. OnValidate: d='-1' i='-1' P='111' s='111' S='' v='all' V='focusin'
W='.37650024'
3. OnValidate: d='0' i='0' P='' s='111' S='111' v='all' V='key'
W='.37650024'
4. OnValidate: d='1' i='0' P='9' s='' S='9' v='all' V='key' W='.37650024'
5. OnValidate: d='1' i='1' P='99' s='9' S='9' v='all' V='key' W='.37650024'
6. OnValidate: d='1' i='2' P='999' s='99' S='9' v='all' V='key'
W='.37650024'

I work on Windows 7, python 2.7.
Anybody know why it happens?



--
View this message in context: 
http://python.6.n6.nabble.com/tkinter-Entry-validation-insert-instead-of-replace-tp5006800.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to