user16174931
user16174931

Reputation:

How to reset the button action in tkinter after every click?

While I learning about the buttons in tkinter. I had a problem with it. I need my button to always reset the old action and want to do the new action.

def clicked():
    res = "THANKYOU " + txt.get()
    res1 = Label(mainwin, text=res, font=("Arial Bold", 35))
    res1.place(relx=0.5,rely=0.5,anchor='center')

In the above program whenever I execute the clicked() function, it must reset the old thank you message and it want show the thank you message with the new values in txt.

Upvotes: 0

Views: 108

Answers (1)

acw1668
acw1668

Reputation: 46669

You need to create the thank you message res1 outside clicked() and update its text using res1.config(text=...) inside clicked() instead:

def clicked():
    res = "THANKYOU " + txt.get()
    res1.config(text=res)

...
res1 = Label(mainwin, font=("Arial Bold", 35))
res1.place(relx=0.5, rely=0.5, anchor='center')
...

Upvotes: 1

Related Questions