Real basic question about Entry box's data

RS Solutions richard_chamberlain at ntlworld.com
Wed Jun 7 03:47:13 EDT 2000


from Tkinter import *
root=Tk()
entry=Entry(root)
var=StringVar()
entry2=Entry(root,textvariable=var)
entry.pack(side=TOP)
entry2.pack(side=TOP)

def calculate():
    var.set(entry.get())

button=Button(root,text="Calculate",command=calculate)
button.pack(side=RIGHT)
root.mainloop()

Getting and setting an Entry widget is straightforward. In the above example
I've used entry.get() to get the contents of a widget and I've used the
textvariable option to set the value.

var=StringVar()

This creates an instance of StringVar that we can assign to our entry.

entry2=Entry(root,textvariable=var)

So every change to var is now reflected in the widget.

var.set(entry.get())

I'm simply changing var to the contents of entry. Obviously here you'll need
to do some calculations and pass that as a string.

In the Grayson book look at the appendices at the back to check out the
methods and options of Entry.

Richard



kent snyder <__kent__ at excite.com> wrote in message
news:8hkqde$9cv$1 at leopard.it.wsu.edu...
> I'm trying to capture an Entry box's value and then print it out.
Actually
> I'd like to do some math with it and return the answer to another Entry
box.
> I have the Grayson book and I can't find any SIMPLE, DIRECT guidance on
> this.  Can anyone offer direction or a link to some sample code that's not
> all cluttered up?
>
> I'd like to NOT use PMW if at all possible.
>
> Thanks a LOT in advance,
> Kent
>
>





More information about the Python-list mailing list