Притом,
canvas.delete("all")
Удаляет только текст, но кнопки - нет.
Вот код, если что:
from tkinter import * import time import random import sys tk = Tk() r = random s = sys t = time tk.title("Aqua-Drive") tk.resizable(0, 0) tk.wm_attributes("-topmost") canvas = Canvas(tk, width="600", height="600", bg="aqua") canvas.place(x=0, y=0) canvas.pack() def play_func(): canvas.delete("all") top_text = text(275, 50, "Levels", "blue", 48) def set_func(): canvas.delete("all") top_text = text(275, 50, "Settings", "blue", 48) def exit_func(): canvas.delete("all") top_text = text(275, 50, "Do you really wanna exit?", "blue", 24) menu = [play_btn, set_btn, exit_btn] for x in range(0, 2): menu.pop(0) def yes_func(): canvas.delete("all") top_text = text(275, 50, "Do you really wanna exit?", "blue", 24) s.exit() def no_func(): canvas.delete("all") top_text = text(275, 50, "Do you really wanna exit?", "blue", 24) yes_btn = buttons("YES", yes_func, 0.25, 0.5, "white", "black", 64) not_btn = buttons("NOT", no_func, 0.75, 0.5, "black", "white", 64) def back_func(): None class buttons: def __init__(self, txt, func, x, y, bg, fg, ft): self = Button(tk, text=txt, command=func, bd=5, background=bg, foreground=fg, font=ft).place(relx=x, rely=y) class text: def __init__(self, x, y, txt, fg, fs): self = canvas.create_text(x, y, text=txt, fill=fg, font="Verdana %s" % fs) top_text = text(275, 50, "Aqua-Drive", "blue", 48) play_btn = buttons("PLAY", play_func, 0.375, 0.3525, "aqua", "dimgrey", 64) set_btn = buttons("SETTINGS", set_func, 0.35, 0.5525, "aqua", "dimgrey", 64) exit_btn = buttons("EXIT", exit_func, 0.3825, 0.7525, "aqua", "dimgrey", 64) while 1: tk.update() tk.update_idletasks() t.sleep(0.01)