Akascape / CTkListbox

A simple listbox for customtkinter (extenstion/add-on)
MIT License
130 stars 14 forks source link

Is it possible to support the get(self, index=None) integer type? #29

Closed JaGwonLim closed 6 months ago

JaGwonLim commented 7 months ago

First of all, I am sorry for my lack of English skills.

I'm using your module really well. I used an integer type to get the value of the list box, but it's a little inconvenient because the developed module only supports character types.

Therefore, I'd like to ask if you can support an integer type. This is a simple modification of the code.


def get(self, index=None):
    """ get the selected value """
    if index or index == 0:
        if str(index).lower()=="all":
            return list(item.cget("text") for item in self.buttons.values())
        else:
            if isinstance(index, int): index = str(index)
            index = list(self.buttons.keys())[int(index)]
            return self.buttons[index].cget("text")
    else:
        if self.multiple:
            return [x.cget("text") for x in self.selections] if len(self.selections)>0 else None
        else:
            return self.selected.cget("text") if self.selected is not None else None

Akascape commented 6 months ago

@JaGwonLim Done