TK entry pretext

Eric Brunel eric.brunel at pragmadev.com
Wed Jan 29 04:02:59 EST 2003


vector180 wrote:
> HI
> Status=ActivePython,xp,newbie
> 
> Im having trouble with the Entry code in TK
> <snip>
> self.e_fanon=Entry(frame,width=5)
> self.e_fanon.grid(row=l_row,column=1,sticky=W)
> <endsnip>
> Q1 can I put some pre text in the entry box?. How?

There are two ways to do that:
1/ use:
self.e_fanon=Entry(frame, width=5, text="default value")
This is not the best way...

2/ use a Tkinter string variable:
myVar = StringVar()
myVar.set("default value")
self.e_fanon=Entry(frame, width=5, textvariable=myVar)
This is the preffered way, since from now, every change made by the user in the 
entry will be reflected in myVar. To get the current value in the entry, just do 
a myVar.get()

> Q2 how do I know when/if to get the users entry?
>         does Python/tk set a flag.

The when or if is up to you. It's usually when a "OK" button is clicked or when 
a "File"/"Save" menu item is chosen or whatever. I can always react to any 
keypress in the entry, but I don't think this is what you want...

HTH
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list