Reputation: 11
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()
Upvotes: 0
Views: 144
Reputation: 1967
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")
Upvotes: 1