[Tutor] Showing/hiding widgets in Tkinter

The Green Tea Leaf thegreentealeaf at gmail.com
Wed Apr 6 13:26:51 CEST 2011


>> According to the documentation I've read I should be able to use
>> 'place()' after having used 'place_forget()' to show the label at the
>> same place.
>
> Where did you read that? I only found
>
> """
> If the configuration of a window has been retrieved with place info, that
> configuration can be restored later by first using place forget to erase any
> existing information for the window and then invoking place configure with
> the saved information.
> """
>
> at http://www.tcl.tk/man/tcl8.5/TkCmd/place.htm

The docs I've found are rather sketchy on almost everything, but I -
perhaps wrongly - interpreted the text at
http://books.google.com/books?id=JnR9hQA3SncC&lpg=PA445&ots=Jb1TEw-42A&dq=tkinter%20place_forget&pg=PA445#v=onepage&q=place_forget&f=false
to mean that I would be able to do this.

An alternative way of interpreting this (and other texts) is that I
should be able to show it again by using the place command with the
same parameters ... but that doesn't work either.

> which implies that tk does not store the placement information
> automatically. Assuming that Python's Tkinter behaves the same way you can
> write
>
> def toggle():
>    if mylabel.visible:
>        mylabel.pi = mylabel.place_info()
>        mylabel.place_forget()
>    else:
>        mylabel.place(mylabel.pi)
>    mylabel.visible = not mylabel.visible

Unfortunately, it doesn't work. I can see the label flashing when I
press the button but it's not visible unless I press the button again.

-- 
The Green Tea Leaf   thegreentealeaf at gmail.com   thegreentealeaf.blogspot.com


More information about the Tutor mailing list