Tkinter: Make it go away!

Martyn Quick mrq at for.mat.bham.ac.uk
Thu Apr 26 07:36:32 EDT 2001


On Wed, 25 Apr 2001, Rick Pasotto wrote:

> > On the line with ???, what can I write to get only one label? How do I 
> > croak an object prematurely?
> 
> Is there some reason not to just change the text in the label that's
> already there?
> 
> lab1.config(text='simple 2')
> 
> If you insist on putting up with the possible flickering as the window
> resizes:
> 
> lab1.destroy()

Another way which is quite useful is to use the forget method.  Here's an
example that worked (provided I've not mistyped anything):

import Tkinter
root = Tkinter.Tk()

button = Tkinter.Button(root, text="I'm a button!")
button.pack()

label = Tkinter.Label(root, text="But I'm a label!")
label.forget()

def switch():
    button.forget()
    label.pack()

button.config(command=switch)

Clicking on the button will hide the button and display the label.  Plenty
more fun and games can be had with this sort of idea.

Martyn
(who's really proud of the fact that this is the first time he's posted a
useful comment to this newsgroup rather than simply a "I'm
stuck!" question)

--------------------------------------------------------
Dr. Martyn Quick  (Research Fellow in Pure Mathematics)
University of Birmingham, Edgbaston, Birmingham, UK.
http://www.mat.bham.ac.uk/M.R.Quick






More information about the Python-list mailing list