Tkinter Object show and hide
Russell E. Owen
owen at nospam.invalid
Tue Aug 20 17:44:36 CEST 2002
In article <3b55ea60.0208191517.96dc162 at posting.google.com>,
mauro at mr-potatohead.com (Mauro) wrote:
>Somebody can talk me if there are some option or function to hide and
>show objects in Tkinter...
What you do is ungrid or unpack the object to hide it, then grid or pack
it again to show it. If you want to it to reappear where it was before
then I strongly suggest using the grid geometry manager for two reasons:
- The gridder offers the grid_remove() method which remembers all your
grid options. Pack has no equivalent.
- Even if you don't take advantage of grid_remove() you can more easily
put something back where it was by specifying row and column (which does
not change) than by trying to reinsert a packed object in the right
place (which requires using the "before" or "after" option to pack().
myobj = Label(...)
myobj.grid() # to regrid at the old location
The other methods that hide objects are pack_forget() (if you packed the
object) or grid_forget() (if you gridded it). Both of these methods
forget the old configuration, so you'll have to provide full info when
you re-show the object with pack(...) or grid(...).
P.S. I assume you know, but never mix grid and pack. Use one geometry
manager or the other within a particular master frame or widget.
More information about the Python-list