- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to keep selections highlighted in a Tkinter Listbox?
Let us consider a situation for a particular system that we have to keep selecting multiple files from a directory and once copied in the clipboard paste all of them into another directory. The idea of making the multiple selections in ListBoxes can be done by using the exportselection property. It allows a Listbox to keep the selection alive while selecting an item from another ListBox. 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") 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, "Python") listboxA.insert(2, "Java") listboxA.insert(3, "C++") listboxA.insert(4, "Rust") listboxA.insert(5, "GoLang") listboxB.insert(1, "C#") listboxB.insert(2, "JavaScript") listboxB.insert(3, "R") listboxB.insert(4, "Php") 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 the listboxes.
Advertisements