"Unmatched open bracket" error when adding an item to ttk.Treeview

I am trying to add an element to a ttk.Treeview instance in my Python script that creates the base interface. The insert code is as follows:

 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 found that when setting the line todo_text in a column named "text" Tkinter throws an error when it encounters a specific line:

_tkinter.TclError: unmatched open bracket in list

and the only thing I can consider the reason for this is that the specified string contains curly braces. Here is the line where it broke:

'// static class Properties { // TODO, temp class'

It seems to happen if I use todo_text or str(todo_text) .

Is the text string parsed somehow? What am I missing?

+4
source share
2 answers

In it is the core, Tkinter is a wrapper around the Tcl interpreter. For Tcl, 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 , then the Tcl error is related to the fact that you have unbalanced curly braces.

It looks like a Tkinter error for me - the tkinter wrapper does not correctly quote data before passing it to the Tcl interpreter. When you set the backslash before the curly brace, now it becomes a valid Tcl string, so you no longer see the error.

This is reported in the python error debugger as issue # 15861

+3
source

Tkinter sits on top of Tcl, which uses curly braces as a kind of quote.

It seems that Tkinter is quoting a line with curly braces for Tcl, but does not escape what is happening in the line itself.

+2
source

All Articles