Hi,
Thus spoketh Helmut Jarausch <[email protected]>
unto us on Wed, 19 Jan 2011 19:32:56 +0100:
> Hi,
>
> I have an Entry widget called Data, whose <Return> event is bound to a
> handler. If this handler recognizes invalid data I clear the
> corresponding textvariable and set the focus to itself by calling
> Data.focus_set(). Then I return "break".
> Thus I'd like to let the user re-enter his data.
> Unfortunately this doesn't work, the focus always proceeds to the next
> Entry widget.
> What am I missing?
I am not sure what you actually did and what goes wrong, does the folowing
code work for you ?
##########################################################
from Tkinter import *
root = Tk()
e = Entry(root)
e.pack(padx=100, pady=100)
e2 = Entry(root)
e2.pack(padx=100, pady=100)
def on_return(event):
if event.widget.get() == 'foo':# the only allowed value :)
print 'That was correct!'
event.widget.event_generate('<Tab>')
else:
print 'That was wrong!'
event.widget.bell()
event.widget.select_range(0, 'end')
e.bind('<Return>', on_return)
e2.bind('<Return>', on_return)
root.mainloop()
##########################################################
Maybe you would also want to have a look at the Entry's validatecommand
option or (if it is an option for you) to look at the Pmw.EntryField
which has excellent validation mechanisms.
Regards
Michael
.-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-.
"That unit is a woman."
"A mass of conflicting impulses."
-- Spock and Nomad, "The Changeling", stardate 3541.9
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss