python - Using <<ListboxSelect>> With More Than One Listbox -
i'm trying use multiple listboxes means of displaying tree of information.
# dictionary: {str : [str]} dict_ = {some_class.get_dictionary()} dict_keys = list[dict.keys()] dict_keys.sort() def selected_item(val): list_box_2.delete(0, end) sender = val.widget index = sender.curselection() value = sender.get(index) thing in dict[value]: list_box_2.insert(end, thing) list_box_1 = listbox(display_frame, selectmode=single) item in dict_keys: list_box_1.insert(end, item) list_box_1.bind("<<listboxselect>>", selected_item) list_box_1.grid(sticky=w+e+n+s) def display_selected(val): sender = val.widget index = sender.curselection() value = sender.get(index) # here call methods value, value class. # in turn should populate third list_box can't there. print(value) list_box_2 = listbox(display_frame, selectmode=single) list_box_2.bind("<<listboxselect>>", display_selected) list_box_2.grid(column=0, row=1, sticky=w+e) list_box_1 works intended: displays dictionary keys, , when user clicks on 1 of items, populates list_box_2 contents of dictionary @ key selected. however, when click on items in list_box_2, calls selected_item() instead of display_selected (or maybe calls both, hard tell), causes content list_box_2 deleted (because of list_box_2.delete(0, end)). believe because of binding "<<listboxselect>>", i'm not certain.
is there way achieve functionality i'm looking for? i've looked around , racked brain can't find information this.
thanks
you should include exportselection=0 option in tkinter listbox, when have more 1 of them onscreen @ same time. default without option bizarre mode in list selection tied system clipboard; simultaneous selections in multiple lists cannot exist (and you're trashing user might have put in clipboard themselves).
Comments
Post a Comment