Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
903 views
in Technique[技术] by (71.8m points)

python - ttk Treeview selection_set can't accept spaces

I'm building a gui using tkk in python and I'm having trouble with the Treeview command selection_set(). I'm trying to use it to set the default selection when my program starts but it seems that it can't accept a string with spaces in it.

tree.selection_set("Sunset Grill")

Causes:

return self.tk.call(self._w, "selection", selop, items)
_tkinter.TclError: Item Sunset not found

Can anyone give any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You might try the following:

tree.selection_set('"Sunset Grill"')

I'm guessing this based on the code for ttk.py and my limited understanding of Tcl. The call to tree.selection_set() calls self.selection("set", items), which in turn calls self.tk.call(self._w, "selection", selop, items) where selop is 'set' and items is the string initially passed to selection_set().

I'm not sure if the self.tk.call() is doing any massaging of the arguments before passing them to Tcl as it's a call into the _tkinter.c module and I don't know enough about the Python/C interface to grok that code. ;)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...