Akascape / CTkListbox

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

Found a wierd bug in the get() function #31

Closed infiniteTesch closed 6 months ago

infiniteTesch commented 7 months ago
def get(self, index=None):
    """ get the selected value """
    if index:
        if str(index).lower()=="all":
            return list(item.cget("text") for item in self.buttons.values())
        else:
            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

It could deliver the value from all indexes above 1 back to the program, except 0.

It was really frustrating when trying to remove multiple items in the list but I couldn't grab the first item in the list. This is a revised version that did the trick:

  def get(self, index=None):
      """ get the selected value """
      if index is not None:  # Changed this line
          if str(index).lower() == "all":
              return list(item.cget("text") for item in self.buttons.values())
          else:
              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

@infiniteTesch Fixed