from Tkinter import *

root = Tk()

button = Button(text="Push me", command=toggle)
button.pack()

label = Label(text="Hello")
label.pack()

def toggle():
    if label.winfo_ismapped():
        button['text']='unmap'
        label.pack_forget()
    else:
        button['text']='map'
        label.pack()

root.wait_window()

Specialties:
IT/Science/Contracts/Religious translation/interpreting FIN-ENG-FIN
Python programming

1
Contributor
1
Reply
7
Views
7 Years
Discussion Span
Last Post by pyTony
0

def should go in beginning, sorry.

from Tkinter import *
def toggle():
    if label.winfo_ismapped():
        button['text']='unmap'
        label.pack_forget()
    else:
        button['text']='map'
        label.pack()

root = Tk()

button = Button(text="Push me", command=toggle)
button.pack()

label = Label(text="Hello")
label.pack()

root.wait_window()
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.