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: ttk.TreeView (and maybe other functions) is overzealous in converting item values to ints
Type: Stage:
Components: Tkinter Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: abarnert, serhiy.storchaka
Priority: normal Keywords:

Created on 2018-08-21 04:49 by abarnert, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg323819 - (view) Author: Andrew Barnert (abarnert) * Date: 2018-08-21 04:49
See this StackOverflow question for a repro case: https://stackoverflow.com/questions/51941260/

If you store a string that looks like an int in a TreeView's values, then call widget.item(row), the dict's 'values' value has that string converted to an int.

This seems reasonable, because it's legal to store an int in a TreeView, and if tkinter didn't convert the values, you'd store 123 and get back '123'.

However, I think it should only be converting strings that could be a valid Tcl int. If you store the int 123_456, Tcl of course gives you back '123456', not '123_456', so there's no reason for tkinter to convert '123_456' to an int. But it does, because ttk._tclobj_to_py just does a try: return int(s).

---

Maeanwhile, if you instead call widget.item(row, options='values'), the string is left alone. 

At first glance, that made sense. But looking into what tkinter is getting back from Tcl, there's really no difference here. The tuple ('180518-23', '23/06/18') is no more or less conversion-worthy than the same tuple inside the list (<option object: '-text'>, '', <option object: '-image'>, '', <option object: '-values'>, ('180518-23', '23/06/18'), <option object: '-open'>, 0, <option object: '-tags'>, ''). It's just that ttk._val_or_dict doesn't call _tclobj_to_py on the value when it gets back a key-value pair, and I don't see why it shouldn't.

However, that turns out to be a handy workaround for the Stack Overflow user who ran into this problem, so maybe it's better not to change that.
History
Date User Action Args
2022-04-11 14:59:04adminsetgithub: 78628
2018-08-21 05:53:15serhiy.storchakasetnosy: + serhiy.storchaka
2018-08-21 04:49:03abarnertcreate