How not lose Listbox selection (tkinter) with exportselection=False

Tkinter is a module for pyhton to create graphic user interfaces (GUI). It is a built in module, so it's free and you do not need to install it, because it is just there.

To avoid losing the selection of an item in a tkinter listbox when you select something outside of the listbox, you can use exportselction=False as argument when you call an istance of the class tkinter.Listbox

    def listbox():
        "The book chapter name list goes here"
        self._lbx = tk.Listbox(
            self._frame,
            bg="yellow",
            exportselection=False # To mantain the selection in the listbox when you select in the text box
            # selectmode=tk.MULTIPLE
            )
        self._lbx.grid(
            column=0,
            row=0,
            sticky="nswe"
            ) # adapt the listbox to the frame
        # self._lbx.configure(selectmode="")

''' this is how you avoid losing selection in tkinter listbox '''
How to not lose selection in a listbox

Subscribe to the newsletter for updates
Tkinter templates
My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts