[Tutor] Newbie-Getting input from a text entry
richard
python@keep-trying.com
Fri, 23 Aug 2002 14:00:24 +0100
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