<KeyPress>, focus, and Pmw widgtes

Marc mnations at airmail.net
Thu Apr 3 19:02:54 EST 2003


Hi,

I was trying to use a keypress to trigger an event in a Gui. Reading
through past postings I discovered that the widget has to have focus
to actually register the event. However, even setting the focus on the
widget component I am unable to trigger the event. Obviously doing
something wrong, I look to the masses for help. Here is my code:

    def widgets(self):
	self.fps = Pmw.EntryField(self.master, labelpos=W, label_text='FPS:',
                                   entry_width=10, validate=None,
value = '0')
	self.fps.pack(side=LEFT, padx = 5)
        self.fps.bind( '<Leave>', self.getTBPS)
        self.fps.bind( '<KeyPress-Up>', self.getTBPS)
    
	entry = self.fps.component('entry')
        entry.focus()


    def getTBPS(self, event):
        print "INTO TBPS"
        fps = int( self.fps.getvalue() )
        length = int( self.size.getvalue() )
        
        #fps = rate * pow(10,6) / ( ( ( length + 4) * 8) + 64)
        tbps = fps /  ( pow(10,6) / ( ( ( length + 4) * 8) + 64) )

        self.tbps.clear()
        self.tbps.setvalue(tbps)

So when I start the application, I assume that the entry widget has
focus. But when I enter data, the keypresses still aren't registered.
But I know that the callback works because when I leave the space, my
<Leave> trigger is registered. What am I missing?

Thanks,
Marc




More information about the Python-list mailing list