I have constructed a listbox using tkinter Now I want the user to click on an item in the listbox that creates a variable with the selection.
- Code: Select all
index = listbox.curselection()
seltext = listbox.get(index)
This properly prints out the selection. However, I am unable to get the "seltext" out of the function and able to use it later in the code. Someone recommended the get_list(event) however I don't know where event came from. Appreciate the help
Your "seltext" is a local variable that exits only inside the function get_list().
If the function is part of a class, and it should be, then you can define your variable as self.seltext. Thereafter, you can use it as such elsewhere in the class, or outside the class as "classname.seltext".