[Tkinter-discuss] Python->Tcl lists

Jeff Epler jepler at unpythonic.net
Tue Mar 23 08:14:17 EST 2004


Python tuples, including nested tuples, are converted to Tcl lists.
Lists are just converted to strings.

>>> import Tkinter
>>> tk = Tkinter.Tk().tk
>>> tk.call("list", [1, "a b", 3, "{"])   # A list is just converted
"\\[1,\\ 'a\\ b',\\ 3,\\ '\\{'\\]"        # as by str()
>>> tk.call("list", (1, "a b", 3, "{"))   # A tuple is converted
'{1 {a b} 3 \\{}'                         # to a tcl list
>>> tk.call("list", (1, (2, 3, "a b"), "c d")) # Nested example
'{1 {2 3 {a b}} {c d}}'
>>> tk.call("list", 1, "a b", 3, "{")     # Positional args are quoted
'1 {a b} 3 \\{'                           # as needed

So where you're trying to do
    text.insert(0.0, "blah", [other, args, here])
you should try
    text.insert(0.0, "blah", tuple([other, args, here]))
or 
    text.insert(0.0, "blah", *[other, args, here])
or
    text.insert(0.0, "blah", other, args, here)

I just did the following and got "what I expected":
>>> import Tkinter
>>> t = Tkinter.Text()
>>> t.tag_configure("red", background="red")
>>> t.tag_configure("blue", background="blue")
>>> t.pack()
>>> t.insert(0.0, "blah", "red", " ", "", "bleep", "blue")

Jeff



More information about the Tkinter-discuss mailing list