N
nholtz
Is there any way to delete a widget (window) from a Text widget, and
then add it back
to the Text, without re-creating the original widget. For example, I
think I would like to do
something like the following:
##########################################################
from Tkinter import *
root = Tk()
textWidget = Text( root )
textWidget.pack()
#### create some widgets
widgets = [ Label( textWidget, text=" Hello World #%d! " % (i,) ) \
for i in range(3) ]
#### add all of them to Text
for widget in widgets:
posn = textWidget.index(INSERT)
textWidget.window_create( posn, window=widget )
#### delete the last one from Text
widget - widgets[-1]
textWidget.delete( posn ) # doesn't delete from children of Text
widget.destroy() # this doesn't seem to make any diff, but it does
delete from children
#### try to add it again
textWidget.window_create( posn, window=widget ) #### FAILS !!!
root.mainloop()
###############################################
That last window_create fails with:
_tkinter.TclError: bad window path name ".1076792812.1076865452"
I woule like to create a number of widget objects, then add / subtract
/ re-add them in
a predicatable order (stack-like)
I'm trying to implement 'Wizard-like' behaviour, but in a single Text
window, where
you step through in small chunks, adding new widgets, but are able to
step backwards
by deleteing them. I was hoping not to have to re-create the widgets
again when
moving forwards, as I was hoping for an easy way to maintain the state.
thanks
neal
then add it back
to the Text, without re-creating the original widget. For example, I
think I would like to do
something like the following:
##########################################################
from Tkinter import *
root = Tk()
textWidget = Text( root )
textWidget.pack()
#### create some widgets
widgets = [ Label( textWidget, text=" Hello World #%d! " % (i,) ) \
for i in range(3) ]
#### add all of them to Text
for widget in widgets:
posn = textWidget.index(INSERT)
textWidget.window_create( posn, window=widget )
#### delete the last one from Text
widget - widgets[-1]
textWidget.delete( posn ) # doesn't delete from children of Text
widget.destroy() # this doesn't seem to make any diff, but it does
delete from children
#### try to add it again
textWidget.window_create( posn, window=widget ) #### FAILS !!!
root.mainloop()
###############################################
That last window_create fails with:
_tkinter.TclError: bad window path name ".1076792812.1076865452"
I woule like to create a number of widget objects, then add / subtract
/ re-add them in
a predicatable order (stack-like)
I'm trying to implement 'Wizard-like' behaviour, but in a single Text
window, where
you step through in small chunks, adding new widgets, but are able to
step backwards
by deleteing them. I was hoping not to have to re-create the widgets
again when
moving forwards, as I was hoping for an easy way to maintain the state.
thanks
neal