[Tutor] Newbie-Getting input from a text entry

Don Arnold darnold02@sprynet.com
Fri, 23 Aug 2002 09:22:43 -0500


The problem is that the geometry managers (pack, place, and grid) return
None instead of the object they're acting on. You'll want to instantiate
your widget,  then grid() it separately:

self.code=Pmw.EntryField(self.root)
self.grid(row=0, column=1,padx=6, pady=2)

Don

----- Original Message -----
From: "richard" <python@keep-trying.com>
To: <tutor@python.org>
Sent: Friday, August 23, 2002 8:00 AM
Subject: [Tutor] Newbie-Getting input from a text entry


> Greetings,
>
> I am trying to retrieve a value from a text box. However I am unable to do
> so as I cannot
> find the correct method to retrieve the value. When I run the script the
> GUI is created fine. The problem occurs when you press the button to
> retrieve the value. I get an error which I think is saying that the get()
> method is not valid, however it is what is used in the examples I have
been
> looking at and these have worked.  I just do not understand why the value
> cannot be assigned.
>
> Any help appreciated.
>
> Richard
>
>
> Error Message:
>
> Exception in Tkinter callback
> Traceback (most recent call last):
>    File "C:\PYTHON22\lib\lib-tk\Tkinter.py", line 1292, in __call__
>      return apply(self.func, args)
>    File "C:\Python22\fmna4.py", line 29, in add
>      print self.code.get()
> AttributeError: 'NoneType' object has no attribute 'get'
>
> Script:
>
> # import modules to be used
> from Tkinter import *
> import Pmw
>
> class GUI:
>      def __init__(self):
> ######################################################################
>          self.root = Tk()
>          self.root.title('FMNA - Add/Amend/Delete')
>          self.root.option_add('*Entry*background',     'lightblue')
>          self.root.option_add('*font',   ('verdana', 10, 'bold'))
>
>          Label(self.root, text='Code').grid(row=0, sticky=W)
>          self.code=Pmw.EntryField(self.root).grid(row=0, column=1,padx=6,
> pady=2)
>
>          Button(self.root, text='Quit', command=self.quit).grid(row=13,
> column=0, columnspan=2)
>          Button(self.root, text='Add', command=self.add).grid(row=13,
> column=3, columnspan=2)
>
>      def quit(self):
>          import sys
>          sys.quit
>
>      def add(self):
>          print self.code.get()
>
> myGUI = GUI()
> #myGUI.root.mainloop()
>
> -----------------------------------------
> Python 2.2
> Platform Win32
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor