Response of selected values in ttk Treeview lags
08:40 14 Jan 2026

I was trying to make an app that shows the values of a table once one of the elements in treeview are selected using the following code:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.title("tk test")
root.geometry("500x300")

def returnText(event):
    global textarea
    textarea.delete("1.0", tk.END)
    textarea.insert("1.0", tree.item(tree.focus())["text"])


tree = ttk.Treeview()
tree.pack(padx=10, pady=10, expand=True, fill=tk.X)

tree.heading("#0", text="contents")

tree.insert("", 0, text="test1")
tree.insert("", 0, text="test2")
tree.insert("", 0, text="test3")

tree.bind("", returnText)

textarea = tk.Text(root)
textarea.pack(expand=True, fill=tk.X, padx=10, pady=10)


root.mainloop()

However, when I run this code, it returns the element that I selected the last time. I bound the treeview with the mouse click "" so it should update the value to the focused ones as soon as an element is selected. What is wrong with this code?

Thanks.

python tkinter treeview ttk