TKinter and focus events

Timothy Grant tjg at avalongroup.net
Sun Jan 23 03:32:52 EST 2000


Hi,

Thanks to some kind assistance from the list I have been able to make
Tkinter do a pretty neat trick (at least I think so!)

Using Pmw.EntryFields, When the field does not have focus it displays
numbers formatted to a specification (e.g., $1,234.56). When the
EntryField gets the focus it reformats the number stripping out the
eye-candy (e.g., 1234.56). To make sure the user enters the correct
info, I turn on either 'integer' or 'real' validation when the
EntryField has focus, and turn it off before I set it to the prettified
entry.

It all work phenomenally well, and I'm tremendously pleased with how
easy it was to convert a number in to nicely formatted text with commas.
However, there is one minor annoyance, every time I move focus to the
field I get what sounds like an error beep, everything works correctly,
I just get this beep, I've been trying to track it down but haven't been
able to figure it out yet. It appears to occur when I do the setentry()
call with the unprettified number. Does anyone have any ideas what might
be happening?

    def FmtEstWt(self, event):
        # Event type 9 is FocusIn and type 10 is FocusOut
        if event.type == '9':   #FocusIn
            print 'EstWt FocusIn'
            self.EstWt.configure(validate='integer')
            self.tmp = string.replace(self.EstWt.get(),',', '')
            self.tmp = string.replace(self.tmp, '$', '')
            self.EstWt.setentry(self.tmp)	#Beep appears to go off here.
        else:                   #FocusOut
            print 'EstWt FocusOut'
            self.EstWt.configure(validate=None)
           
self.EstWt.setentry(commanumber(string.atoi(self.EstWt.get()),0,0))

OK, I just thought of something just before I hit my send button, so I
actually setup an "invalidcommand" option for the EntryField. Sure
enough, the invalid function gets called when I do the setentry. This
does not stop the setentry from working though. I've dumped the contents
of self.tmp, and it appears to be a clean string that if I keyed by hand
would pass the validation no problem.

-- 
Stand Fast,
    tjg.

Chief Technology Officer              tjg at exceptionalminds.com
Red Hat Certified Engineer            www.exceptionalminds.com
Avalon Technology Group, Inc.                   (503) 246-3630
>>>>>>>>>>>>Linux...Because rebooting isn't normal<<<<<<<<<<<<




More information about the Python-list mailing list