Closed KellyOBrian closed 4 years ago
Hello Kelly,
Thank you for your question. Unfortunately it highlights a previously-unnoticed potential issue in Tcl::pTk. This may take some figuring out, as this involves an important part of Tcl::pTk that I still don't understand too well.
I would normally have expected to be able to refer to the Tcl/Tk ttk::treeview manual and then try adapting to the Perl/Tk syntax, especially since ttkTreeview isn't something that was in Perl/Tk (and would've had an adapted manual for it). Widget commands should map to Perl methods, and options map to parameters of those methods. So for getting selected row(s) of a tree would be
.tree selection
in Tcl syntax, and
$tree->selection
in Perl syntax.
The .tree selection
command in Tcl returns a list of selected items (rows), which have default names like I001
, I002
, …, I009
, I00A
, …, I00F
, I010
, etc. But I notice that Tcl::pTk returns this command's result as a string (with Tcl list syntax) rather translating it to a Perl list, which might not be what is expected.
Had it returned a Perl list, I could then try getting the values for the first selected item:
$tree->item(($tree->selection)[0], '-values')
which should be equivalent to
.tree item [.tree selection] -values
The .tree item
command in Tcl also returns a list, but again Tcl::pTk does not appear to be translating this command's result into a Perl list either.
I will keep investigating, and hopefully soon provide a better answer and a new release of Tcl::pTk with improved ttkTreeview usability.
(Edit: fixed syntax errors)
I have published Tcl::pTk 1.08 with improvements to ttkTreeview usage. For example, you can now do:
($tree->item(($tree->selection)[0], '-values'))[0]
to get the value in the leftmost column of the first selected row.
Is there still something else you were trying to find information on?
This is brilliant. It works perfectly for me. No other information needed yet. Thank you!
You're welcome!
Not an issue. More a question. The widgetTclpTk has a ttkTreview example. Where is the info for accessing the functionalities of this widget from Tcl::pTk? For example, how do I get the values of the highlighted row?
Thx