On Mon, 6 Feb 2006 20:11:28 -0700, Bob Greschke <bo*@greschke.c om> wrote:
Hi!
I want to grab the contents of a Text widget when the frame it's on gets
destroyed. I tried TextWidget.bind ("<Destroy>" ... , but the widget is
gone
before the call gets made, and I'd really hate to do something with the
function that gets called with TextWidgetsFram e.bind("<Destro y>", ...,
since
that one function handles all of the frames in the program...or would
that
even work?
How can I do this?
One way is to define the deletion callback for the text's parent window to
get the text before the widget gets deleted. To do that, you can use
text.winfo_topl evel() to get the parent Toplevel for your text widget,
then define the callback via wdw.protocol('W M_DELETE_WINDOW ', ...). Here
is a detailed example:
-----------------------------------------------------
from Tkinter import *
root = Tk()
txt = None
def openWdw():
global txt
wdw = Toplevel()
frm = Frame(wdw)
frm.pack(expand =1)
txt = Text(frm)
txt.pack()
print txt.winfo_tople vel(), frm, root
txt.winfo_tople vel().protocol( 'WM_DELETE_WIND OW', getText)
def getText():
print txt.get(1.0, END)
txt.winfo_tople vel().destroy()
Button(root, text='Go', command=openWdw ).pack()
root.mainloop()
-----------------------------------------------------
This will of course only work if the only reason for which the text widget
can be destroyed is if its parent window is closed.
HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17;8(%,5.Z65\ '*9--56l7+-'])"