954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Demonstrating Tkinter pack and pack_forget

0
By Tony Veijalainen on Apr 17th, 2010 1:52 am

Also demonstrate changing the text of the widgets label dynamically.

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()

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()
pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: