richardiontton
Technical User
I have a few pieces of code here, the first piece is not written by myself and is taken from another program, basically I cannot reference the entry widgets in the standard fashion(second piece of code, ie. def newHost(self)). When the style of writing is that of the code below, How do you reference the Entry widget? :
iframe2 = Frame(frame, bd=2, relief=RIDGE)
Label(iframe2, text='Hostname widget:').pack(side=LEFT, padx=5)
hn_var = StringVar()
Entry(iframe2, textvariable=hn_var, bg='white').pack(side=RIGHT, padx=5)
hn_var.set('Entry widget')
iframe2.pack(expand=1, fill=X, pady=10, padx=5)
def newHost(self):
'Clear the fields in the window(except the listbox)'
self.hn_var.delete(0, END)
Here is the error message :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__
return self.func(*args)
File "C:\mynewapp.py", line 228, in newHost
self.hn_var.delete(0, END)
AttributeError: App instance has no attribute 'hn_var'
iframe2 = Frame(frame, bd=2, relief=RIDGE)
Label(iframe2, text='Hostname widget:').pack(side=LEFT, padx=5)
hn_var = StringVar()
Entry(iframe2, textvariable=hn_var, bg='white').pack(side=RIGHT, padx=5)
hn_var.set('Entry widget')
iframe2.pack(expand=1, fill=X, pady=10, padx=5)
def newHost(self):
'Clear the fields in the window(except the listbox)'
self.hn_var.delete(0, END)
Here is the error message :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__
return self.func(*args)
File "C:\mynewapp.py", line 228, in newHost
self.hn_var.delete(0, END)
AttributeError: App instance has no attribute 'hn_var'