How can I access the 'Entry' string in another function?
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Tue Jul 4 02:52:52 EDT 2006
In <1151993240.681919.297130 at v61g2000cwv.googlegroups.com>, arvind wrote:
> i've created the myclass instance and calles the "function second()".
> i want to access the text entered in 'w' through Entry widget in
> "function third()"
> i am getting the 'fuction not having 'w' attribute error.
> how to overcome it?
Make `w` an attribute of the object. When you create the widget in
`second()` you just bind it to the local name `w` instead of `self.w`.
You made a similar mistake when printing `senter` in `third()`. This
time it's the other way around: you are trying to print a non-existing
local `senter` instead of `self.senter`. This works:
import Tkinter as tk
class MyClass:
senter = 'arvind'
def third(self):
self.senter = self.w.get()
print self.senter
def second(self):
top = tk.Tk()
top.title('second')
frame = tk.Frame(top)
self.w = tk.Entry(top)
b1 = tk.Button(top, text='Next', command=self.third)
self.w.grid()
b1.grid()
frame.grid()
top.mainloop()
a = MyClass()
a.second()
More information about the Python-list
mailing list