/Demo/tkinter/matt/entry-simple.py

http://unladen-swallow.googlecode.com/ · Python · 24 lines · 14 code · 6 blank · 4 comment · 0 complexity · 11c16e8b520ce40094d5d5c96424c34a MD5 · raw file

  1. from Tkinter import *
  2. import string
  3. # This program shows how to use a simple type-in box
  4. class App(Frame):
  5. def __init__(self, master=None):
  6. Frame.__init__(self, master)
  7. self.pack()
  8. self.entrythingy = Entry()
  9. self.entrythingy.pack()
  10. # and here we get a callback when the user hits return. we could
  11. # make the key that triggers the callback anything we wanted to.
  12. # other typical options might be <Key-Tab> or <Key> (for anything)
  13. self.entrythingy.bind('<Key-Return>', self.print_contents)
  14. def print_contents(self, event):
  15. print "hi. contents of entry is now ---->", self.entrythingy.get()
  16. root = App()
  17. root.master.title("Foo")
  18. root.mainloop()