n0trad3an
n0trad3an

Reputation: 21

How can i make this text entry/frame as a whole disappear?

So I want to make this frame that I made disappear after the press of a button. Heres the code:

import tkinter as tk

root = tk.Tk()
root.geometry("150x50+680+350")

def FormSubmission():
    global button_start
    root.attributes("-fullscreen", True)
    frame = tk.Frame(root)
    tk.Label(frame, text="First Name:").grid(row=0)
    entry1 = tk.Entry(frame)
    entry1.grid(row=0, column=1)
    tk.Label(frame, text="Last Name:").grid(row=1)
    e2 = tk.Entry(frame)
    e2.grid(row=1, column=1)
    tk.Label(frame, text="Email:").grid(row=2)
    e3 = tk.Entry(frame)
    e3.grid(row=2, column=1)
    tk.Label(frame, text="Date of Birth:").grid(row=3)
    e4 = tk.Entry(frame)
    e4.grid(row=3, column=1)
    frame.pack(anchor='center', expand=True)
    button_next = tk.Button(root, text = "Next", height = 2, width = 7, command = MainPage).pack()
    button_start.place_forget()

def MainPage():
    global FormSubmission
    root.attributes("-fullscreen", True)
    l1 = tk.Label(root, text = "Welcome Back,"   , font = ("Arial", 44)).pack()
    button_start.place_forget() # You can also use `button_start.destroy()`






button_start = tk.Button(root, text="Start", height=3, width=20, command = FormSubmission)
button_start.place(x = 0, y = 10)
button_exit = tk.Button(root, text="Exit", command=root.destroy)
button_exit.place(x=1506, y=0)

root.mainloop()

So as you see I want to make the frame/function (FormSubmission) for the entry field disappear after pressing the next button after in the function (MainPage).

Upvotes: 0

Views: 39

Answers (1)

David Meu
David Meu

Reputation: 1545

You can use pack_forget

Every geometry manager(pack, grid, place) has its own ..._forget

I've re-edit your snippet just for the use case you wished for.

Anyway I think you should re-design your app.

import tkinter as tk

root = tk.Tk()
root.geometry("150x50+680+350")

def FormSubmission():
    global button_start
    root.attributes("-fullscreen", True)
    frame = tk.Frame(root)
    tk.Label(frame, text="First Name:").grid(row=0)
    entry1 = tk.Entry(frame)
    entry1.grid(row=0, column=1)
    tk.Label(frame, text="Last Name:").grid(row=1)
    e2 = tk.Entry(frame)
    e2.grid(row=1, column=1)
    tk.Label(frame, text="Email:").grid(row=2)
    e3 = tk.Entry(frame)
    e3.grid(row=2, column=1)
    tk.Label(frame, text="Date of Birth:").grid(row=3)
    e4 = tk.Entry(frame)
    e4.grid(row=3, column=1)
    frame.pack(anchor='center', expand=True)
    button_next = tk.Button(root, text = "Next", height = 2, width = 7, command = lambda: MainPage(frame)).pack()
    button_start.place_forget()

def MainPage(frame):
    global FormSubmission
    frame.pack_forget()
    root.attributes("-fullscreen", True)
    l1 = tk.Label(root, text = "Welcome Back,"   , font = ("Arial", 44)).pack()
    button_start.place_forget() # You can also use `button_start.destroy()`

button_start = tk.Button(root, text="Start", height=3, width=20, command = FormSubmission)
button_start.place(x = 0, y = 10)
button_exit = tk.Button(root, text="Exit", command=root.destroy)
button_exit.place(x=1506, y=0)

root.mainloop()

Upvotes: 1

Related Questions