Author terry.reedy
Recipients anish.shah, gbarnabic, serhiy.storchaka, terry.reedy
Date 2016-02-20.03:44:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1455939854.96.0.645533121858.issue26386@psf.upfronthosting.co.za>
In-reply-to
Content
The 3.5 version of 2015 Dec 6 is 3.5.1. A traceback is not a crash for the purpose of this tracker.

It is generally a good idea to mention OS, OS version, and Tk Version. (IDLE displays TkVersion in Help => About IDLE.)  However, on Win 10 (8.6.4), I was able to reproduce with all four of the .selection_xyz(items) methods, which are all specializations of the .selection(op, items) methods.

import tkinter as tk
from tkinter import ttk
root = tk.Tk()
tree = ttk.Treeview(root)
tree.pack()
tree.insert('', 1, iid='a b', text='id with space')
for item in tree.get_children():
    print(item)
    #tree.selection_add(item)  # fail
    #tree.selection_toggle(item)  # fail
    #tree.selection_set(item)  # fail
    #tree.selection_remove(item)  # fail
    tree.selection('add', item)  # fail

getting

a b
Traceback (most recent call last):
  File "F:\Python\mypy\tem.py", line 10, in <module>
    tree.selection_toggle(item)
  File "C:\Programs\Python35\lib\tkinter\ttk.py", line 1415, in selection_toggle
    self.selection("toggle", items)
  File "C:\Programs\Python35\lib\tkinter\ttk.py", line 1395, in selection
    return self.tk.call(self._w, "selection", selop, items)
_tkinter.TclError: Item a not found

tkinter 


These are the only Treeview methods in which a single argument can be multiple items.  The doc string and doc do not define the form of 'items'.  The unofficial but generally helpful doc, http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Treeview.html says "The argument may be either a single iid or a sequence of iids."  I would expect sequence mean a tuple of strings, not space-separated fields in a string (a tcl sequence).

The .delete and .detach methods have signature '*items', meaning that each item is passed as a separate argument.  The methods them pass the tuple of strings to tk.  This should have been the signature of the selection methods.

Putting a single string in a tuple solves the problem, as in.

    tree.selection('add', (item,))

My suggested fix is to add a statement to .selection

    def selection(self, selop=None, items=None):
        """If selop is not specified, returns selected items."""
        if isinstance(items, str):  # new
            items = (items,)
        return self.tk.call(self._w, "selection", selop, items)
History
Date User Action Args
2016-02-20 03:44:15terry.reedysetrecipients: + terry.reedy, serhiy.storchaka, anish.shah, gbarnabic
2016-02-20 03:44:14terry.reedysetmessageid: <1455939854.96.0.645533121858.issue26386@psf.upfronthosting.co.za>
2016-02-20 03:44:14terry.reedylinkissue26386 messages
2016-02-20 03:44:13terry.reedycreate