Giter VIP home page Giter VIP logo

Comments (4)

infiniteTesch avatar infiniteTesch commented on July 25, 2024

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.

Radian327 avatar Radian327 commented on July 25, 2024

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.

infiniteTesch avatar infiniteTesch commented on July 25, 2024

Ah nice! Ty for sharing

from ctklistbox.

Akascape avatar Akascape commented on July 25, 2024

Tried to fix the issue, test to new version.

from ctklistbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.