In Tcl, for a listbox, there is a 'selectioncommand', but Page's attribute editor for listbox does not have that value, am I missing something. Also no ' <<ListboxSelect>> ' in bindings for listbox. How do you specify or retrive the value selected for use in the code?
Last edit: Anonymous 2017-08-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The listbox man page does not indicate selectcommand as an option. And Tcl configure command does not return a selectcommand option.
As far as the <<ListboxSelect>> virtual event, I am not sure why it does not appear in the bindings editor. I will look into that. In the meantime you can get to the Bindings Editor and select select the listbox entry, Insert->Advanced..., and add <<ListboxSelect>> to the Event entry box and select the Add button. Then continue to specify the callback function.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2018-10-31
Hi Don, did you look into this issue? I have run across the same thing... assuming the Listbox would have a selection mechanism but finding now it doesn't appear to. I've tried the steps you listed and added <<listboxselect>> to the Listbox bindings editor, but nothing new appears in the configure() calls for the listbox nor is 'selectioncommand' a legal kwarg.</listboxselect>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have just looked into your question and created an example where I used <<listboxselect>> and it worked. Note the case.</listboxselect>
PAGE uses the Tk command "event info" to get "a list of all the virtual events that are currently defined." But <<listboxselect>> is not in the list nor is included in the Event manpage. It is described in the Listbox man page. I don't know why. So I guess that you will have to visit the man pages to be sure.</listboxselect>
I'm responding now that I'm logged in I can track replies (and maybe edit?). The markdown formatting appears to be messing with the << and >> as well as case; sorry I didn't note that in the first request above. Using PAGE 4.17.
The TCL manual does list <<ListboxSelect>> so I kept working with that. In PAGE's bindings window I did as you described above and added <<ListboxSelect>> with the advanced pane, and provided a function for the lambda assignment. However, when generating the GUI .py file the appropriate bind() statement never gets generated.
When I manually add the bind() statement to the GUI .py file to assign the function to the <<ListboxSelect>> virtual event, then yes, it does work. The function gets called with an event when a line in the listbox is selected.
However, it appears that the event is always the same no matter which line in the listbox is selected, which is how the documentation defines it (https://www.tcl.tk/man/tcl/TkCmd/event.htm#M44). Is there an obvious thing I'm missing? The TCL documentation mentions that the underlying TCL should return a list of indices of selected lines as a curselection command response: https://www.tcl.tk/man/tcl8.5/TkCmd/listbox.htm#M18
Update:
Aha, I tried 4.18 and the bind() statement is now correctly generated in the GUI .py, but I am not sure how to distinguish the selected line(s).
Last edit: Mike Klein 2018-11-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
After the <<listboxselect>> event occurs and takes you to the callback routine, the following in the callback routine will get the index of the selected entries:</listboxselect>
index= w.Listbox1.curselection()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My application produces a growing list of lines for the listbox, over several seconds (10, 20). The first selection of a line, even while the list is still growing, works perfectly.
Each time more lines should be displayed, I set the listvariable to the full set of lines known at that time, and they all display correctly. However, none of the lines following the one I initially selected will produce a callback.
If I wait until all lines are found before selecting any of them, and listvariable contains the full set of lines, then all the lines produce correct callback functionality. But selecting a line before all of them have been sent to listvariable seems to set a barrier above which selection doesn't work. Is there a reset required before updating listvariable?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By digging into the TCL commands and finding the mapping between TCL commands and the supported listbox functions using the dir(listbox) Python function, I've been able to get this to work, as far as I've tested. It appears that the listboxVar.set() function does not clear previous state or something.
Instead, I'm doing the following:
Before starting a new search of items to display in the listbox, clear the existing selection and listbox with listbox.selection_clear(0, 'end') and listbox.delete(0, 'end')
As each new item is found, determine in which position it should appear in the sorted list and do listbox.insert(new_position, new_string), where new_position is an integer index or the string 'end' if it goes at the end of the list
So, not using the listboxVar at all, and manipulating the list through lower-level TCL commands mapped to the Python interface.
There's still one small issue left, which is that the underlining left over from the previous selection seems to persist even after clearing the selection.
Last edit: Mike Klein 2018-11-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "PAGE - Discussion"
In Tcl, for a listbox, there is a 'selectioncommand', but Page's attribute editor for listbox does not have that value, am I missing something. Also no ' <<ListboxSelect>> ' in bindings for listbox. How do you specify or retrive the value selected for use in the code?
Last edit: Anonymous 2017-08-29
The listbox man page does not indicate selectcommand as an option. And Tcl configure command does not return a selectcommand option.
As far as the <<ListboxSelect>> virtual event, I am not sure why it does not appear in the bindings editor. I will look into that. In the meantime you can get to the Bindings Editor and select select the listbox entry, Insert->Advanced..., and add <<ListboxSelect>> to the Event entry box and select the Add button. Then continue to specify the callback function.
Hi Don, did you look into this issue? I have run across the same thing... assuming the Listbox would have a selection mechanism but finding now it doesn't appear to. I've tried the steps you listed and added <<listboxselect>> to the Listbox bindings editor, but nothing new appears in the configure() calls for the listbox nor is 'selectioncommand' a legal kwarg.</listboxselect>
Hi,
I have just looked into your question and created an example where I used <<listboxselect>> and it worked. Note the case.</listboxselect>
PAGE uses the Tk command "event info" to get "a list of all the virtual events that are currently defined." But <<listboxselect>> is not in the list nor is included in the Event manpage. It is described in the Listbox man page. I don't know why. So I guess that you will have to visit the man pages to be sure.</listboxselect>
For some reason the last post did not show an upper case L and upper case S in <<listboxselect>>. </listboxselect>
I'm responding now that I'm logged in I can track replies (and maybe edit?). The markdown formatting appears to be messing with the
<<
and>>
as well as case; sorry I didn't note that in the first request above. Using PAGE 4.17.The TCL manual does list
<<ListboxSelect>>
so I kept working with that. In PAGE's bindings window I did as you described above and added<<ListboxSelect>>
with the advanced pane, and provided a function for the lambda assignment. However, when generating the GUI .py file the appropriatebind()
statement never gets generated.When I manually add the
bind()
statement to the GUI .py file to assign the function to the<<ListboxSelect>>
virtual event, then yes, it does work. The function gets called with an event when a line in the listbox is selected.However, it appears that the event is always the same no matter which line in the listbox is selected, which is how the documentation defines it (https://www.tcl.tk/man/tcl/TkCmd/event.htm#M44). Is there an obvious thing I'm missing? The TCL documentation mentions that the underlying TCL should return a list of indices of selected lines as a
curselection
command response: https://www.tcl.tk/man/tcl8.5/TkCmd/listbox.htm#M18Update:
Aha, I tried 4.18 and the
bind()
statement is now correctly generated in the GUI .py, but I am not sure how to distinguish the selected line(s).Last edit: Mike Klein 2018-11-01
After the <<listboxselect>> event occurs and takes you to the callback routine, the following in the callback routine will get the index of the selected entries:</listboxselect>
Bingo! Works great! Thanks Don!
Spoke too soon....
My application produces a growing list of lines for the listbox, over several seconds (10, 20). The first selection of a line, even while the list is still growing, works perfectly.
Each time more lines should be displayed, I set the
listvariable
to the full set of lines known at that time, and they all display correctly. However, none of the lines following the one I initially selected will produce a callback.If I wait until all lines are found before selecting any of them, and
listvariable
contains the full set of lines, then all the lines produce correct callback functionality. But selecting a line before all of them have been sent tolistvariable
seems to set a barrier above which selection doesn't work. Is there a reset required before updatinglistvariable
?By digging into the TCL commands and finding the mapping between TCL commands and the supported listbox functions using the
dir(listbox)
Python function, I've been able to get this to work, as far as I've tested. It appears that thelistboxVar.set()
function does not clear previous state or something.Instead, I'm doing the following:
listbox.selection_clear(0, 'end')
andlistbox.delete(0, 'end')
listbox.insert(new_position, new_string)
, wherenew_position
is an integer index or the string'end'
if it goes at the end of the listSo, not using the
listboxVar
at all, and manipulating the list through lower-level TCL commands mapped to the Python interface.There's still one small issue left, which is that the underlining left over from the previous selection seems to persist even after clearing the selection.
Last edit: Mike Klein 2018-11-01