By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,538 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,538 IT Pros & Developers. It's quick & easy.

How can I access the 'Entry' string in another function?

P: n/a
hi all,
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?
class myclass:
senter='arvind'

def __init__(self):
return None

def third(self):
self.senter=self.w.get()
print senter

def second(self):
top=Tk()
frame=Frame(top)
frame.master.title("second")

strobj=StringVar()
w=Entry(top)

b1=Button(top,text='Next',command=self.third)

w.grid()
b1.grid()
frame.grid()

mainloop()

Jul 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In <11**********************@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()

Jul 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.