0

I’m working on a project that uses tkinter and the buttons. So lets say my window has a text 'hi' and a button that displays 'bye' when I click it. When I click it 'hi' is replaced with 'bye', but I want to append 'bye'. How do I stop it from replacing my existing text?

This is my code:

from tkinter import *

window = Tk()
window.title("Welcome ")
window.geometry('1000x200')
    
lbl = Label(window, text="Hi")
lbl.grid(column=0, row=0)

def click():
    lbl.configure(text="bye")

btn = Button(window, text="click here", command=click)    
btn.grid(column=1, row=0)
    
window.mainloop()

1 Answer 1

1

You can use cget to get the content, then update it as you wish; for instance:

def click():
    lbl.configure(text=lbl.cget('text')+" bye")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.