Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Python Tk echo - change text of label

  • Entry

  • Label

  • Button

  • Entry window, Button, Label where to show the text we typed in.

import tkinter as tk

def echo():
    print('echo')
    label['text'] = entry.get()

app = tk.Tk()
app.title('Echo')

entry = tk.Entry(app)
entry.pack()

label = tk.Label(app, text="", width=10, anchor="w")
label.pack()


echo_button = tk.Button(app, text="Echo", command=echo)
echo_button.pack()

exit_button = tk.Button(app, text="Exit", fg="red", command=app.destroy)
exit_button.pack()

app.mainloop()