Hide & Remove DISCLAIMER: I promise the good stuff is coming back. We have to go through the valley to get to the mountain, right? Sometimes, we want to remove a button, image or piece of text from the screen. To do this, we use pack_forget(). π We'll start with our default tkinter program. import tkinter as tk window = tk.Tk() window.title("Hello World") window.geometry("300x200") hello = tk.Label(text = "Hello World") hello.pack() button = tk.Button(text = "Click me!") button.pack() tk.mainloop() π Now I'm going to add a new subroutine to hide the label and call it on a button click. import tkinter as tk window = tk.Tk() window.title("Hello World") window.geometry("300x200") # New subroutine def hideLabel(): hello.pack_forget() # Removes the 'hello' label hello = tk.Label(text = "Hello World") hello.pack() button = tk.Button(text = "Click me!", command = hideLabel) # Call...


Comments
Post a Comment