Making entrys work with tkinter.
Brian Elmegaard
be at mek.dtu.dk
Wed Mar 28 06:29:37 EST 2001
Hi group,
I have been trying to find out how to use the an entry and grab the
result. I am sorry, that I have not been able to figure out from
different sources how bind the entry to an event and make it put back
the result to the calling function.
What I try is:
class Sheetlabel:
def __init__(self,canvas,x,y):
self.frame=Toplevel(width=10,height=20)
self.frame.title('Insert label')
Label(self.frame,text='Label:').pack(side='left')
self.entry=Entry(self.frame)
#FIX THIS
self.frame.bind('<Return>',self.ok(x,y,canvas))
self.entry.pack(side='right')
self.frame.focus_set()
def ok(self,x,y,canvas,event=None):
self.text=self.entry.get()
self.frame.destroy()
canvas.create_text(20+x,20+y,text=self.text)
return self.text
which should put the label text on the canvas. With a create_text in
__init__ there is no problem. So somehow I think I am struggling with
scopes. Is that right?
--
Brian
http://www.et.dtu.dk/energysystems
http://www.rk-speed.dk http://fiduso.dk http://sunsite.auc.dk/dk-tug
\TeX, tak
More information about the Python-list
mailing list