[Tkinter-discuss] [Python-Dev] Binding problem

Michael Lange klappnase at web.de
Wed Jan 15 10:22:01 CET 2014


Hi Rob,

> On Tue, Jan 14, 2014 at 4:53 PM, Rob Ward <rl.ward at bigpond.com> wrote:
(...)
> > I am am having trouble binding an Entry widget to <Return>
> >
> > Here is the snippet (butCol is a Frame widget to put buttons,labels
> > and text entry down LHS)
> >
> > KS1=StringVar()
> > KS1.set("Key is ??")
> > butCol.ks1
> > =Label(butCol,textvariable=KS1).grid(column=0,row=18,sticky=(N,W))
> >
> > myKey = [0,2,4,5,7,9,11] #Begin in the key of C
> > KS2       =StringVar()
> > KS2.set("C")
> > butCol.ks2
> > =Entry(butCol,width=20,textvariable=KS2).grid(column=0,row=19,sticky=
> > (N,W))
> >
> > The above lines all render correctly, but will not trigger off
> > "entry" of data at all on <Return>

Yes, by default pressing the Retrun key on an Entry widget simply does
nothing.

> >
> > Adding the following line just crashes.
> >
> > butCol.ks2.bind("<Return>",chooseKey)

I cannot reproduce this crashing here, so I suspect it might have
something to do with chooseKey() ?
To help to track down the problem you might try to run the following
very simple example:

from tkinter import *

root = Tk()

var = StringVar()
var.set('foo')
l = Label(root, textvariable=var)
l.pack()

def test(event):
    print(var.get())

e = Entry(root, textvariable=var)
e.pack()
e.bind('<Return>', test)

root.mainloop()

Does this work for you or crash either?

(...)
> > One overall observation that has frustrated me is how toi search for
> > information that relates to Python3 and the latest tkinter modules.
> > I kept finding old python or old Tkinter or combinations of both.
> > Wrorking my way through this was very time consuming and rarely
> > productive.  Is there any advice on how to get the "latest"
> > information off the WWW?

There are at least two excellent Tkinter reference manuals available
online:

http://effbot.org/tkinterbook/tkinter-index.htm by Frederik Lundh and
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html by John W.
Shipman.

There are practically no changes in Tkinter between Python2 and -3
(except that Tkinter in Python3 is now spelled "tkinter" :), so both of
these are still valid.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

I object to intellect without discipline;  I object to power without
constructive purpose.
		-- Spock, "The Squire of Gothos", stardate 2124.5


More information about the Tkinter-discuss mailing list