
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to select at the same time from two Tkinter Listbox?
Let us consider a situation for a particular system to keep selecting multiple files from a directory and, once copied in the clipboard, paste them into another directory. The idea of making multiple selections in ListBoxes can be implemented by using the exportselection property. The property prevents the selected options from losing while choosing an item from another ListBox. Thus, we can select multiple options from the ListBoxes. To configure a Listbox to behave like keep selection steady, we can make exportselection = False.
Example
#Import Tkinter library from tkinter import * #Create an instance of Tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x350") #Create ListBoxes listboxA=Listbox(win, exportselection=False) #Create listboxA listboxA.pack(padx=10,pady=10,fill=BOTH,expand=True) listboxB=Listbox(win,exportselection=False) #Create ListboxB listboxB.pack(padx=10,pady=10,fill=BOTH,expand=True) listboxA.insert(1, "1.Python") listboxA.insert(2, "2.Java") listboxA.insert(3, "3.C++") listboxA.insert(4, "4.Rust") listboxA.insert(5, "5.GoLang") listboxB.insert(1, "a.C#") listboxB.insert(2, "b.JavaScript") listboxB.insert(3, "c.R") listboxB.insert(4, "d.Php") listboxB.insert(5, "e.CoffeeScript") listboxB.insert(6, "f.Curl") win.mainloop()
Output
Running the above code will display a window that contains two listboxes. While making a selection, we can select multiple items from both listboxes.
- Related Articles
- Default to and select the first item in Tkinter Listbox
- How to show multiple Canvases at the same time in Tkinter?
- How to clear a Tkinter ListBox?
- How to fit Tkinter listbox to contents?
- How to edit a Listbox item in Tkinter?
- How to fully change the color of a Tkinter Listbox?
- How to display a Listbox with columns using Tkinter?
- How to keep selections highlighted in a Tkinter Listbox?
- How to select one item at a time from JCheckBox in Java?
- How to remove multiple selected items in the listbox in Tkinter?
- How can I change the text of the Tkinter Listbox item?
- How to directly modify a specific item in a TKinter listbox?
- Resize the Tkinter Listbox widget when the window resizes
- How to catch many exceptions at the same time in Kotlin?
- Attach scrollbar to listbox as opposed to window in Tkinter

Advertisements