469,580 Members | 1,898 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,580 developers. It's quick & easy.

Tkinter: ability to delete widgets from Text and then re-add them

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

May 12 '06 #1
2 2563
Sigh. Of course, near the middle is supposed to be:

#### delete the last one from Text
widget = widgets[-1]

May 12 '06 #2
I now see that I can accomplish what I want using the Canvas widget,
instead of the
Text widget (I.e., I can create a window on it, delete the window, then
re add it without
recreating the underlying widget object).

As I don't want the raw contents user-editable, I guess its better to
use a Canvas, rather
than a Text (slightly harder to use, though, I guess)

neal

May 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Thomas Buschhardt | last post: by
3 posts views Thread by Phil Schmidt | last post: by
3 posts views Thread by rick.lawson | last post: by
25 posts views Thread by BJörn Lindqvist | last post: by
3 posts views Thread by Matt Hammond | last post: by
1 post views Thread by Michael Yanowitz | last post: by
2 posts views Thread by python programming newb | last post: by
1 post views Thread by vigacmoe | last post: by
4 posts views Thread by MartinRinehart | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.