Tkinter focus_get()

dsavitsk dsavitsk at e-coli.net
Sat Mar 10 15:39:57 EST 2001


I have a grid (actually a dictionary of dictionaries) of entry widgets that
are dynamically created.  Each has <KeyPress> bound to it.  I am trying to
determine which one has focus, so i used

self.root.focus_get()

which returns something that looks like

.8854796.8898804.18282492.18282532.18283228.18248316.17887444.17854708

is there a way to interpret this? or a better way to get focus?

how the entries are created is shown below (this creates a row of entries in
a ScrolledCanvis)

-----------------------------------------------------
def AddRow(self):
        y = {}
        self.itemnumber = self.itemnumber + 1
        y['lbl'] = str(self.itemnumber) + '.'
        self.data_dict[self.itemnumber] = y
        y['frm'] = Frame(self.ft2.interior(), bg='#AAAAFF')
# frame for entry and label
        Label(y['frm'], width=11, bg='#eeeeee', justify='right',
wraplength=172, text=y['lbl']).pack(side=LEFT, fill=X, expand=YES)
        for i in ['a', 'b', 'c', 'd', 'e']:
            y[i + 'd'] = StringVar()                                     #
entry's data
            y[i + 'e'] = Entry(y['frm'], relief='solid', borderwidth=0,
textvariable=y[i + 'd'])
            y[i + 'e'].bind('<KeyPress-Up>', self.reportUp)
            y[i + 'e'].bind('<KeyPress-Down>', self.reportDown)
            y[i + 'e'].bind('<KeyPress-Left>', self.reportLeft)
            y[i + 'e'].bind('<KeyPress-Right>', self.reportRight)
            y[i + 'e'].pack(side=LEFT, expand=YES, fill=X, padx=1, pady=1)
        y['frm'].pack(side=TOP, expand=YES, fill=X, padx=0, pady=0)
        self.grid[self.itemnumber] = y
------------------------------------------------------

thanks again,

doug





More information about the Python-list mailing list