Comments (4)
I use a populate listbox function that reads from a separate pool source, in my case a folder with .txts.
I can remove and add items seamlessly just by making the changes in the folder and then run this function:
def populate_listbox(self):
# Clear the listbox before populating
while self.listbox.size() > 0:
self.listbox.delete(0)
# Path to the 'lists' folder
lists_folder_path = os.path.join(os.path.dirname(__file__), 'lists')
# Check if the 'lists' folder exists
if os.path.exists(lists_folder_path):
# List all files in the 'lists' folder
file_list = os.listdir(lists_folder_path)
# Filter and sort files using natural sort order
self.sorted_files = sorted(
[file for file in file_list if file.endswith(".txt") and file != '.tmp'],
key=self.natural_sort_key # Pass the function without calling it
)
# Insert each file into the listbox
for file_name in self.sorted_files:
display_name = file_name[:-4] # Remove the '.txt' extension
self.listbox.insert("end", display_name)
# Return a dictionary mapping filenames to their indices
self.file_indices = {file_name: index for index, file_name in enumerate(self.sorted_files)}
#file_name = filename.txt(folder path excluded)
else:
print(f"Folder not found: {lists_folder_path}")
from ctklistbox.
I've found the error is induced when with the call:
listbox.delete("all") #clear entries
AFTER you have already selected entries and then try to add new entries.
The "fix" is to ensure to "deactivate" the selections BEFORE you use the .delete("all")
Use this to clear the list box after it has been used prior.
for i in range(listbox.size()):
listbox.deactivate(i)
listbox.selection_clear()
listbox.delete("all") #clear entries
Thanks
Radian327
from ctklistbox.
Ah nice! Ty for sharing
from ctklistbox.
Tried to fix the issue, test to new version.
from ctklistbox.
Related Issues (20)
- Select event bug HOT 1
- support for .index(option) HOT 3
- Why is it so slow? HOT 2
- Select function broke after last update HOT 2
- Noticed a recursive call on listbox select
- customtkinter light appearance mode makes the list items nearly invisible HOT 1
- Add support for custom themes
- How to bind other events
- List Scrollbar gets stuck when using .delete("all") to migrate from a bigger list to a small one, or am I doing something wrong? HOT 1
- <Question> Need for .after HOT 1
- cannot replace a line index HOT 1
- Error when deleting all in empty listbox HOT 2
- ast.literal_eval() instead of eval() ?
- empty StringVar raise error and cannot create CTkListbox with listvariable
- wraplength?
- Query every options from the listbox HOT 2
- Updating items in the list HOT 5
- Is there an equivalent option to .see(index)? HOT 1
- Unable to get drag-and-drop working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ctklistbox.