This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Delete selected item generate "<>" event or not in different version of tkinter or Python
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jason990420, epaine, serhiy.storchaka
Priority: normal Keywords:

Created on 2021-12-26 10:02 by Jason990420, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg409185 - (view) Author: Jason Yang (Jason990420) * Date: 2021-12-26 10:02
In python(3.8.10)/tkinter(8.6.9), it won't generate "<<TreeviewSelect>>" event if we delete selected item of ttk.Treeview, but it will for python(3.9.9/3.10.1)/tkinter(8.6.12).

Check it just by clicking 'Delete Item 1' button in following demo code

```python
import sys
from random import randint
from datetime import datetime
import tkinter as tk
from tkinter import ttk

def button_callback():
    button.configure(state='disabled')
    treeview.delete(1)

def treeview_callback(event):
    print(datetime.now().strftime("%H:%M:%S"), "Treeview selection changed !")

print(f"Python version : {sys.version.split(' ')[0]}")
print(f"tkinter version: {tk.Tcl().eval('info patchlevel')}")

columns = ('President', 'Birthday')
data = [
    ('Ronald Reagan', 'February 6'),
    ('Abraham Lincoln', 'February 12'),
    ('George Washington', 'February 22'),
    ('Andrew Jackson', 'March 15'),
    ('Thomas Jefferson', 'April 13'),
]

root = tk.Tk()

treeview = ttk.Treeview(root, columns=columns, height=5, show='headings')
treeview.pack()
for column in columns:
    treeview.heading(column, text=column)
    treeview.column(column, width=150)
for i, row in enumerate(data):
    treeview.insert('', i, iid=i, text=str(i), values=row)
treeview.selection_set(1)

button = tk.Button(root, text='Delete Item 1', command=button_callback)
button.pack()

treeview.bind("<<TreeviewSelect>>", treeview_callback)

root.mainloop()
```

```python
d:\>python test3.py
Python version : 3.8.10
tkinter version: 8.6.9
17:57:43 Treeview selection changed !

d:\>python test3.py
Python version : 3.9.9
tkinter version: 8.6.12
17:58:10 Treeview selection changed !
17:58:11 Treeview selection changed !

d:\>python test3.py
Python version : 3.10.1
tkinter version: 8.6.12
18:01:10 Treeview selection changed !
18:01:12 Treeview selection changed !
```
msg409206 - (view) Author: E. Paine (epaine) * Date: 2021-12-26 16:19
Reproduced on Wish 8.6.9 and 8.6.11 (same behaviour on 8.6.11 as reported on 8.6.12).

I can't comment on why this is happening or which is correct behaviour so I would recommend taking it up with the Tk team https://core.tcl-lang.org/tk/reportlist (tkinter is just a thin wrapper of Tk and doesn't modify the event handling code). If you do take it up with them, here's the minimum equivalent Tcl code:

pack [ttk::treeview .t]
pack [button .b -text delete -command {.t delete 0}]
.t insert {} 0 -id 0 -text 0 -values {V1, V2}
bind .t <<TreeviewSelect>> {puts {select}}
.t selection set 0
msg409216 - (view) Author: Jason Yang (Jason990420) * Date: 2021-12-26 18:22
From https://core.tcl-lang.org/tk/reportlist, I found the same issue

ttk::treeview <<TreeviewSelect>> event bug 
https://core.tcl-lang.org/tk/tktview?name=2a6c62afd9

It is an old bug from 2014 anf not fixed, and now it fixed.
OK, no more question about it.

Thank you for your information.



B.R.,

Jason Yng
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90337
2021-12-26 18:22:53Jason990420setstatus: open -> closed
resolution: fixed
messages: + msg409216

stage: resolved
2021-12-26 16:19:10epainesetnosy: + serhiy.storchaka, epaine
messages: + msg409206
2021-12-26 10:02:13Jason990420create