0

Basically I have this application:

window

When I press on one of the buttons it will have a label below. now let's say I want to press on another button, how can I delete the previous label and show the new one?

Ex: if I pressed on dataset 1 it will show yes but then if I pressed on dataset 3 it will delete yes and show maybe.

My code so far:

def printit(number):
    if number == 1:
        Label(win,text="yes",fg="blue",bg="yellow",font = ("Calibri 10 bold")
             ).place(x=12,y=400)
    if number == 2:
        Label(win,text="no",fg="blue",bg="yellow",font = ("Calibri 10 bold")
             ).place(x=12,y=400)
    if number == 3:
        Label(win,text="maybe",fg="blue",bg="yellow",font = ("Calibri 10 bold")
             ).place(x=12,y=400)

win =  Tk()

win.geometry("400x600")
win.configure(background="cyan")
win.title("Ensemble Method")

title = Label(win, text="AdaBoost", bg="gray", width="300", height="2", fg="white",
              font = ("Calibri 20 bold italic underline")).pack()
canvas= Canvas(win, width= 400, height= 600, bg="cyan")

#Add a text in Canvas
canvas.create_text(200, 30, text="choose which dataset you want", fill="black",
                   font=('Helvetica 15 bold'))
canvas.pack()

dataset_1 = Button(win, text="dataset 1", width="12",height="1",activebackground="violet",
                   bg="Pink", command=lambda: printit(1),font = ("Calibri 12 ")
                  ).place(x=20, y=200)
dataset_2 = Button(win, text="dataset 2", width="12",height="1",activebackground="violet",
                   bg="Pink", command=lambda: printit(2), font = ("Calibri 12 ")
                  ).place(x=150, y=200)
dataset_3 = Button(win, text="dataset 3", width="12",height="1",activebackground="violet",
                   bg="Pink", command=lambda: printit(3),font = ("Calibri 12 ")
                  ).place(x=280, y=200)

win.mainloop()

martineau
  • 112,593
  • 23
  • 157
  • 280
mouhamad
  • 23
  • 2
  • 2
    you don't create a new label, you use `config` on an already existing label and there are questions with answers on this site about this – Matiiss Dec 03 '21 at 20:08

0 Answers0