How can you completely remove all the widgets that are present in the tkinter window tkinter this code as an example:

 from tkinter import * tk = Tk() tk.title('Разрушители') main_lbl = Label(tk, text='Приветствую в "Разрушителях"', fg='red', font='Arial 20') wellcome_lbl = Label(tk, text='Бродя по лесу ты наткнулся на своего первого противника - ' 'ВОЛКА \n эти опасные твари никогда не отступают , так что В БОЙ!!!!!', fg='black', font='Arial 20') next_btn=Button(tk, text='Далее', width=30, height=5, font=20) def next1(event): pass #Как сделать что бы кнопка всё удаляла? next_btn.bind(tk, next1) main_lbl.pack() wellcome_lbl.pack() next_btn.pack() tk.mainloop() 

    1 answer 1

    Using the dectroy function, dectroy can destroy objects. An example on your code:

     from tkinter import * def next_1(): destroy_object = [welcome_lbl, main_lbl, next_btn] for object_name in destroy_object: object_name.destroy() tk = Tk() tk.title('Разрушители') main_lbl = Label(tk, text='Приветствую в "Разрушителях"', fg='red', font='Arial 20') welcome_lbl = Label(tk, text='Бродя по лесу ты наткнулся на своего первого противника - ВОЛКА' '\n эти опасные твари никогда не отступают, так что В БОЙ!!!!!', fg='black', font='Arial 20') next_btn = Button(tk, text='Далее', width=30, height=5, font=20, command=next_1) main_lbl.pack() welcome_lbl.pack() next_btn.pack() tk.mainloop() 

    Also, if you continue to use those widgets that you want to "temporarily hide", you can use .pack() instead of .grid() and hide objects with winfo.viewable() and make them visible again.

    Example

     from tkinter import * def next_1(): destroy_object = [welcome_lbl, main_lbl] for object_name in destroy_object: if object_name.winfo_viewable(): object_name.grid_remove() else: object_name.grid() tk = Tk() tk.title('Разрушители') main_lbl = Label(tk, text='Приветствую в "Разрушителях"', fg='red', font='Arial 20') welcome_lbl = Label(tk, text='Бродя по лесу ты наткнулся на своего первого противника - ВОЛКА' '\n эти опасные твари никогда не отступают, так что В БОЙ!!!!!', fg='black', font='Arial 20') next_btn = Button(tk, text='Далее', width=30, height=5, font=20, command=next_1) main_lbl.grid() welcome_lbl.grid() next_btn.grid() tk.mainloop()