TKinter Entry question

Jørgen Cederberg jorgencederberg at hotmail.com
Fri Jan 31 03:25:56 EST 2003


vector wrote:
> Q1 can I put some pre text in the entry box?. How?
> Q2 how do I know when/if to get the users entry?

This is the second time you ask these questions. Eric Brunel gave you a 
hint to use StringVar() and a button. Here is an example that reacts to 
all that is entered in the entry field.

--- Start ---
# entry.py
from Tkinter import *

def textentered(event):
     pass

class EntryTester:
     def __init__(self, parent, deftext):
         self.fanon = StringVar()
         e = Entry(parent, textvariable=self.fanon)
         e.pack()
         e.bind('<Key>', self.keybhit)
         self.fanon.set(deftext)

     def keybhit(self, event):
         print self.fanon.get()

if __name__ == '__main__':
     import sys
     root = Tk()
     EntryTester(root, sys.argv[1])
     root.mainloop()

--- End ---

it should be runned as: python entry.py DefaultText

But reading your posting again, suggest that the fanon variable is a 
switch perhaps? In that case, consider using a radiobutton or 
checkbutton instead.

Execellent Tkinter documentation is found at:
http://www.pythonware.com/library/tkinter/introduction/index.htm and
http://www.nmt.edu/tcc/help/lang/python/tkinter.html

Regards
Jørgen Cederberg








More information about the Python-list mailing list