Please solve my Problem regarding tkinter

Hi everyone. I am currently, a bit confused regarding the insertion of my code

for widget in root.winfo_children():
    widget.destroy():

This Code is used to delete everything being displayed on the screen in Tkinter.

Here is my code:

def new_student():
    head = Label(root, text="New Admission", bg="red", fg="white", font=50, relief=GROOVE).pack(anchor=N, fill=BOTH)
    joining_date = Label(root, text="Date of Joining", bg="light blue", fg="black", font="Times").pack(anchor=N, side=LEFT)
    joining_date_input = Entry(root, bg="white", fg="black", relief=SUNKEN).pack(anchor=N,side=LEFT)
    gap = Label(root, text="", bg="light blue").pack(anchor=N, side=LEFT)
    class_joining = Label(root, text="Class of Joining", fg="black", bg="light blue", font="Times").pack(anchor=N, side=LEFT)
    class_joining_input = Entry(root, bg="white", fg="black", relief=SUNKEN).pack(anchor=N, side=LEFT)
    gap = Label(root, text="", bg="light blue").pack(anchor=N, side=LEFT)
    Surname = Label(root, text="Surname", bg="light blue", fg="black", font="Times").pack(anchor=N, side=LEFT)
    Surname_input = Entry(root, bg="white", fg="black", relief=SUNKEN).pack(anchor=N, side=LEFT)
    gap = Label(root, text="", bg="light blue").pack(anchor=N, side=LEFT)
    pupil_name = Label(root, text="Pupil's Name", bg="light blue", fg="black", font="Times").pack(anchor=N, side=LEFT)
    pupil_name_input = Entry(root, bg="white", fg="black", relief=SUNKEN).pack(anchor=N, side=LEFT)
    gap = Label(root, text="", bg="light blue").pack(anchor=N, side=LEFT)
    father_name = Label(root, text="Father's Name", bg="light blue", fg="black", font="Times").pack(anchor=N, side=LEFT)
    father_name_input = Entry(root, bg="white", fg="black", relief=SUNKEN).pack(anchor=N, side=LEFT)
    gap = Label(root, text="", bg="light blue").pack(anchor=N, side=LEFT)
    mother_name = Label(root, text="Mother's Name", bg="light blue", fg="black", font="Times").pack(anchor=N, side=LEFT)
    mother_name_input = Entry(root, bg="white", fg="black", relief=SUNKEN).pack(anchor=N, side=LEFT)
    gap = Label(root, text="", bg="light blue").pack(anchor=N, side=LEFT)
    class_name = Label(root, text="Class", bg="light blue", fg="black", font="Times").pack()




def back():
    pass


# Defining a function to display Information about Admin della Scuola
def info():
    head = Label(root, text="Admin della Scuola", bg="red", fg="white", font=20, relief=SUNKEN).pack(anchor=N, fill=BOTH)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    main = Label(root, text=body, bg="red", fg="white", relief=SOLID, borderwidth=5, font="Times").pack(anchor=N, fill=BOTH)

# Defining function for check for updates
def check_for_updates():
    version = "Version 1.1"
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    gap = Label(root, text="", bg="light blue").pack(anchor=N)
    update = Label(root, text=f"[ (VERSION) {version} ] Currently, you are updated...", bg="red", fg="white", font=20).pack(anchor=N)
    future_updates = Label(root, text="You will be notified for future Updates...", bg="light blue", fg="black", font="Ariel").pack(anchor=N)
    back_button = Button(root, text="Let's Go Back", bg="white", fg="black", command=back).pack(anchor=N)
    
# Creating a function for contact
def contact():
    con = Label(root, text="Contact details:", bg="red", fg="white", font="Times", relief=SUNKEN).pack(anchor=N)
    email = "email-id"
    instagram = "instagram-acount"
    details = Label(root, text=f"Email ID - {email}", bg="light blue", fg="black", font="Ariel", relief=GROOVE).pack(anchor=N)
    details1 = Label(root, text=f"Instagram - {instagram}", bg="light blue", fg="black", font="Ariel", relief=GROOVE).pack(anchor=N)


# Importing Tkinter
from tkinter import *
root = Tk()
root.title("Admin della Scuola")

# Creating a menubar
menubar = Menu(root)

# Academic Year menu button
academic_year = Menu(menubar, tearoff=0)
# Start writing from here
academic_year.add_command(label="Academic Progress")
academic_year.add_command(label="Academic Attendence")
academic_year.add_command(label="Asset Inventory and Issuance Register")
academic_year.add_command(label="Academic Period Allotment")

menubar.add_cascade(label="Academic Year", menu=academic_year)


# Configuration menubutton
configuration = Menu(menubar, tearoff=0)
# Start writing from here
configuration.add_command(label="Syllabus And Lesson Plan")
configuration.add_command(label="Hall Ticket Generator")
configuration.add_command(label="Parents Teachers Meeting")

menubar.add_cascade(label="Configuration", menu=configuration)


# Dashboard Menubutton
dashboard = Menu(menubar, tearoff=0)
#Start writing from here
dashboard.add_command(label="Dashboard")

menubar.add_cascade(label="Dashboard", menu=dashboard)


#News menubutton
news =Menu(menubar, tearoff=0)
# Start from here
news.add_command(label="Notable Events, Weather and Sports ( NEWS )")
news.add_command(label="Updates")

menubar.add_cascade(label="News", menu=news)


#Course Management Menubutton
course_management = Menu(menubar, tearoff=0)
# Start from here
course_management.add_command(label="Pre - Primary")
course_management.add_command(label="Primary")
course_management.add_command(label="Secondary")
course_management.add_command(label="Higher Secondary")

menubar.add_cascade(label="Course Management", menu=course_management)


# Examination Menubutton
examination = Menu(menubar, tearoff=0)
# Start from here
examination.add_command(label="Examination Timetable")
examination.add_command(label="New Examination")


menubar.add_cascade(label="Examination", menu=examination)


# Student Menubutton
student = Menu(menubar, tearoff=0)
# Start from here
student.add_command(label="New Student", command=new_student)
student.add_command(label="Student Data Viewer")

menubar.add_cascade(label="Student", menu=student)


# Employee Menubutton
employee = Menu(menubar, tearoff=0)
# Start from here
employee.add_command(label="Teacher's Attendence")
employee.add_command(label="School Staff Attendence")
employee.add_command(label="Salary Status")

menubar.add_cascade(label="Employee", menu=employee)


# Attendence Menubutton
attendence = Menu(menubar, tearoff=0)
# Start from here
attendence.add_command(label="Student's Attendence")


menubar.add_cascade(label="Attendence", menu=attendence)


# Timetable Menubutton
timetable = Menu(menubar, tearoff=0)
# Start from here
timetable.add_command(label="Timetable Viewer")
timetable.add_command(label="Update Timetable")

menubar.add_cascade(label="Timetable", menu=timetable)


# Fees Menubutton
fees = Menu(menubar, tearoff=0)
# Start from here
fees.add_command(label="Fees Collection")

menubar.add_cascade(label="Fees", menu=fees)


# Hostel Menubutton
hostel = Menu(menubar, tearoff=0)
# Start from here
hostel.add_command(label="Hostel Asset DataBase")
hostel.add_command(label="Room Vacancy")

menubar.add_cascade(label="Hostel", menu=hostel)


# Transport Menubutton
transport = Menu(menubar, tearoff=0)
# Start from here
transport.add_command(label="Bus")
transport.add_command(label="Student Transportation Details")

menubar.add_cascade(label="Transport", menu=transport)


# Library Menubutton
library = Menu(menubar, tearoff=0)
# Start from here
library.add_command(label="New Entries")
library.add_command(label="Books Status")


menubar.add_cascade(label="Library", menu=library)


# Download Menubutton
download = Menu(menubar, tearoff=0)
# Start from here


menubar.add_cascade(label="Download", menu=download)



# Import menubutton
import_f = Menu(menubar, tearoff=0)
# Start from here


menubar.add_cascade(label="Import", menu=import_f)


# Help Menubutton
help_s = Menu(menubar, tearoff=0)
# Start from here
help_s.add_command(label="About Admin della Scuola", command=info)
help_s.add_command(label="Documentation")
help_s.add_command(label="Check for Updates", command=check_for_updates)
help_s.add_command(label="Contact", command=contact)
help_s.add_separator()
help_s.add_command(label="Exit", command=root.quit)

menubar.add_cascade(label="Help", menu=help_s)

root.config(bg="light blue", menu=menubar)
root.mainloop()

I just wanted to know where should I type the first code in my main code to erase the entire content from the screen, and then the screen can be used for other actions, mentioned in the buttons of the menubar.

Reply me as sson as possible, if anyone finds it's solution

If you place the block to destroy all widgets after the line

root.mainloop()

It will not be executed until you exit from the window. You will not see the work it does but the clean up does happen.

If you place it before you call the main loop, you will loose all the buttons before you exit the window.

Assuming you want to clear the screen, using the block, I would recommend you put the block into a function and then call it as command when a button or menu item is clicked.

root.mainloop keeps the execution within itself until you exit the function or allow calls from the buttons.

hope this helps.