my goal with this code is make something on the screen at the touch of a button (in this case make a text appear) and be able to clear it once i touch another button (using frame clear)
import tkinter as tk
def clear_all_inside_frame():
for widget in frame1.winfo_children():
widget.destroy()
def testo():
text="testo"
text_output = tk.Label(frame1, text=text, fg="red", font=("Helvetica", 16))
text_output.grid(row=0, column=1)
root = tk.Tk()
root.title("clear frame")
root.geometry("400x200")
# Frame
frame1 = tk.Frame(root, width=300, height=100)
frame1.pack()
btn1 = tk.Button(root, text="This is a button inside frame", command=testo())
btn1.pack()
clear_button = tk.Button(root,text="Clear all",command=clear_all_inside_frame)
clear_button.pack(pady=25)
root.mainloop()```
this is my code, once i run it the text alredy appears (without needing to touch the button). once i touch the clear button it clears the text but it dosent re-appear even if i touch the first button.