I’m attempting to add an item to a ttk.Treeview instance in my Python script that builds a basic UI. The insertion code looks like this:
tree.insert(my_id,
'end',
todo_id,
text="Line " + str(line_num),
values=(str(todo_text), owner), # I have 2 cols, 'text' and 'owner'
tags=['#todo_entry'])
I’m finding that when setting the string todo_text in the column named ‘text’, Tkinter throws an error when it encounters a particular string:
_tkinter.TclError: unmatched open brace in list
and the only thing I can think of as the reason for this, is that the string in question contains a curly brace. Here is the string it broke on:
'// static class Properties { // TODO, temp class'
This seems to happen whether or not I use todo_text or str(todo_text).
Is the text string being parsed somehow? What am I missing?
At it’s core, Tkinter is a wrapper around a Tcl interpreter. To Tcl, curly braces are special unless they are escaped. Curly braces are the most common way to create a Tcl list. If you see
unmatched open brace in list, that’s a Tcl error related to the fact that you have unbalanced braces.This looks like a Tkinter bug to me — the tkinter wrapper is incorrectly quoting data before passing it on to the Tcl interpreter. When you place a backslash in front of the curly brace, this now becomes a valid Tcl string, which is why you no longer see the error.
This has been reported on the python bug tracker as issue #15861