[Tutor] Labels??? and Entry fields
Bryce Embry
bryce@bembry.org
Tue, 09 Apr 2002 09:03:34 -0500
In Tkinter, the Entry widget has a method called get() that will retrieve
the information entered in a text field. I'm a bit new to Tkinter, but a
code like this should do the trick:
>>>
from Tkinter import *
root = Tk()
name = Entry(root, width = 30)
name.grid()
# I use grid as a geometry manager. You can use name.pack() or
name.place() instead.
# Type stuff into the entry box
username = name.get()
print username
This is a short example from in IDLE. Most likely, you'll want to set this
up so that it only gets the text when a button is pressed. Here is a short
script for that:
from Tkinter import *
root = Tk()
Label(root, text = "Enter your name").grid(row = 0, column = 0)
namebox = Entry(root, width = 30)
namebox.grid(row = 1, column = 0)
def getname(event):
username = namebox.get()
textbox.insert(END, username)
btn = Button(root, text = "Enter")
btn.bind('<Button-1>', getname)
btn.grid(row = 2, column = 0)
textbox = Text(root, height= 5, width = 20, bg = "blue", fg = "white")
textbox.grid(row = 3, colum = 0)
This script does not compare the text entered to another string. This is
just a script that gets the text and displays it in a blue box on the
window. Hope this helps
Bryce Embry
Geek-of-All-Trades, Master-of-None
--------------------------------------------------------------------------------------------
"Lord, you establish peace for us.
All that we have accomplished
you have done for us" -- Isaiah 26:12