В этом коде при вводе целого числа и нажатии кнопки процесса отображается количество полей ввода. Я хочу, чтобы кнопка «Назад» действовала как кнопка возврата, которая заставляет поля ввода исчезать и приводить GUI в исходное состояние. Как я могу это сделать?
import tkinter as tk
import tkinter.ttk as ttk
hht=[]
tks = []
window = tk.Tk()
def open_window(pll):
numh = int(pll)
l0 = tk.Label(canvas, text="H T", font="Calibri 12", bg="white")
canvas.create_window(390,125, window=l0, anchor=tk.NW)
for i in range(numh):
hht.append(tk.StringVar())
tks.append(tk.StringVar())
en = ttk.Entry(canvas, textvariable = hht[i])
en.config({"background": "gainsboro"})
canvas.create_window(350, 150+i*25, window=en, anchor=tk.NW)
aen = ttk.Entry(canvas, textvariable = tks[i])
aen.config({"background": "gainsboro"})
canvas.create_window(500, 150+i*25, window=aen, anchor=tk.NW)
ws = window.winfo_screenwidth()
hs = window.winfo_screenheight()
w = 700 # width for the Tk root
h = 410 # height for the Tk root
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
window.geometry('%dx%d+%d+%d' % (w, h, x, y))
canvas = tk.Canvas(window,bg="white",width=700, height=410, highlightthickness=0)
canvas.pack()
l13= tk.Label(canvas, text="Enter Numbers", font="Calibri 16", bg="white")
canvas.create_window(300,8, window=l13, anchor=tk.NW)
l0 = tk.Label(canvas, text="Entry", font="Calibri 12", bg="white")
canvas.create_window(15,58, window=l0, anchor=tk.NW)
PLz = tk.DoubleVar()
entry_PLz = ttk.Entry(canvas, textvariable=PLz)
entry_PLz.config({"background": "gainsboro"})
canvas.create_window(270,70, window=entry_PLz)
submit_button = ttk.Button(canvas, text="Process >>", command=lambda: open_window(PLz.get()))
canvas.create_window(300, 100, window=submit_button, anchor=tk.NW)
back_button = ttk.Button(canvas, text="Back")
canvas.create_window(450, 100, window=back_button, anchor=tk.NW)
window.resizable(False, False)
window.mainloop()