Giter VIP home page Giter VIP logo

ctklistbox's Introduction

Typing SVG

⚡ STATS ⚡

Akascape's github streak stats


⚙️ TECH STACK ⚙️


Main OS 3D Video Editing Photo Editing Music Production Compositing IDLE Recording


🌐 MY SOCIALS 🌐



Buy Me a Coffee at ko-fi.com

ctklistbox's People

Contributors

akascape avatar cheemaotb avatar kirangda avatar p0ckey avatar p3rdigas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ctklistbox's Issues

How to change height of listbox

Width is easiliy changeable by .configure(width=...)

But height is not changing. I want the height of the scrollableframe to be modifiable, how shall I achieve this?

<Question> Need for .after

This is not an issue. Just a question I want help with. What is the need of using functions inside .after in line 110,115,119? What if i call these functions instantaneously.

I have created a general code for updating various listboxes in my frame. There are various bindings each triggering this general code to update the listboxes. However, in few of these functions, I am calling the general code+ another code just to update a given listbox. This triggers an error signifying that the listbox has not yet updated through the general code.

To fix this, i removed .after and called each command at the same frame. The script began working fine. However, I want to make sure that this does not have any deeper implications.

Thank You

support for .index(option)

How can I know the index of a given option in the listbox, if it exists. I have an option which is selected. Now, I want to select the option just below it and just above it. I could do it if i know its index. Index can be obtained by any external loops. I was wondering if there is any pre-built function, or do you have anything in mind?

<<ListboxSelect>> event binding not compatible

I have a python gui where I need to keep track of the order in which I select things in the listbox. In order to do this using normal tkinter you have to bind the <> event to the listbox and basically dump the indicies into a list to keep track of the order. Is it possible to either make the <> event binding compatible or add some way to keep track of the order of item selection in the listbox?

To get this to work in tkinter I do the following:

    # Setting up the listbox
    self.listbox = Listbox(root, selectmode=MULTIPLE)
    self.listbox.pack(pady=10, fill="both", expand=True)
    # Bind the selection event
    self.listbox.bind('<<ListboxSelect>>', self.on_listbox_select)
    
    
    def on_listbox_select(self, event=None):
    # Get currently selected items
    current_selection = set(self.listbox.curselection())
    # Determine the new selection (if any)
    new_selection = current_selection - set(self.selection_order)
    # Determine deselected items (if any)
    deselected = set(self.selection_order) - current_selection
    # Remove deselected items from the order list
    self.selection_order = [item for item in self.selection_order if item not in deselected]
    # Add the new selection to the order list
    self.selection_order.extend(new_selection)
    # Debug: Print the order of selection
    print("Selection Order:", [self.listbox.get(i) for i in self.selection_order])

customtkinter light appearance mode makes the list items nearly invisible

Adding customtkinter.set_appearance_mode("light") to the provided example breaks the CTKListbox colors: Only the selected item and hovering items are visible. The other ones are barely visible.

In dark mode it works fine, but light mode is not usable:

ctklistbox-light-broken

ctklistbox-dark-works

Setting a custom text_color tuple is a workaround, but in my opinion the default colors should work out of the box.

Select event bug

I'm facing a perplexing issue that's beyond my current skill level, and I'm hoping for some expert insight. In my project, I'm struggling with managing multiple listboxes, each with distinct select events. Oddly, regardless of whether a specific class is instantiated, selecting an item in any listbox triggers the event linked to the first-created listbox. This behavior persists even though it seems like a fundamental error in my part.

I've spent considerable time troubleshooting but to no avail. It seems like there might be some underlying issue that I'm not equipped to solve. That's where I hope you, the brilliant minds of this community, can come in. Akash, or any other experienced contributor, your expertise on the deeper architecture of this functionality would be invaluable.

To clarify the situation:

EditorListbox(CTkListbox) is in class A with its unique on_click function.
RandomListbox(CTkListbox) is in class B, also with its own on_click function.
Despite EditorListbox not being active (its parent class isn't even instantiated), selecting an item in RandomListbox – which is entirely out of scope – somehow triggers the function connected to EditorListbox.

This behavior is baffling and is a significant roadblock in my project. Any insights, advice, or potential solutions would be greatly appreciated. I'm eager to learn and resolve this issue, and your help could be a turning point.

Thank you in advance for your time and expertise!

The code:

self.listbox = EditorListbox(self, command=self.on_listbox_select)

class EditorListbox(CTkListbox):
    def __init__(self, master, width=200, height=400, fg_color=listbox_fg_color, select_color=listbox_select_color, text_color=listbox_txt_color, font=None, border_color=listbox_border_color, hover_color=hver_color, scrollbar_button_color=scrollbar_color, scrollbar_button_hover_color=scrollbar_hover_color, command=None, **kwargs):
        if font is None:
            font = tk.CTkFont(default_font, size=txt_size)
        super().__init__(master, width=width, height=height, fg_color=fg_color, highlight_color=select_color, text_color=text_color, font=font, border_color=border_color, hover_color=hover_color, scrollbar_button_color=scrollbar_button_color, scrollbar_button_hover_color=scrollbar_button_hover_color, **kwargs)

        self.command = command
        self.bind("<<ListboxSelect>>", self.on_listbox_select)

    def update_theme(self):
        self.configure(
            fg_color=listbox_fg_color, 
            highlight_color=listbox_select_color,  
            border_color=listbox_border_color, 
            hover_color=listbox_select_color,
            text_color = listbox_txt_color,
            scrollbar_button_color=scrollbar_color,
            scrollbar_button_hover_color=scrollbar_hover_color
        )

    def on_listbox_select(self, event):
        if self.command:
            self.command(event)

Removing whitespace in a listbox with a small amount of options

I can't remove the whitespace underneath these 4 options for my listbox. I have tried using the height variable. I am able to make the listbox bigger by setting say height=400, however, I am unable to reduce the height to make a perfect fit for my four items in the listbox.

https://imgur.com/a/3pBL54w

I have also tried reducing the height of the parent, but that just squished the buttons that are at the bottom of my listbox.

cannot replace a line index

ten items in my listbox i want to replace index 5 listbox.delete(5) when i try insert(5,"frogs") it adds it to the end of the list? although it did delete index 5?

Its quite possible I'm doing something wrong? any help sure would be appreciated!

Thanks

Delete All Elements

It would be great if a method could be added to clear all elements of the listbox, makes it easier when you need to refresh it with a new list or a list that has been modified but don't know the index of elements you need to change

Adding multiple modes

The tkinter listbox has modes: tk.SINGLE, tk.BROWSE, tk.MULTIPLE, tk.EXTENDED

i would like to choose items with Shift and Ctrl or to select items with arrows

can you add this pls
sry for my eng :)

CTklistbox scrolling problem when creating more than one CTklistbox

Hi,
First of all, thanks for the library, it saved the day (I needed CTklistboxes for my coding video, and you created one!).
I had this wired problem when I created two CTklistboxes, and when I inserted in both of them, only the last created one was scrolling properly. I tested with three CTklistboxes as well, and the same behavior happened: The two first two CTklistboxes where like fidgeted: the elements were added, but the scrollbar heigh wasn't adapting, so the scrolling became impossible.

To make the scrolling work properly, I had to comment out the definition of the bind method from your source code. And the scrolling worked for both CTklistboxes. I don't why it worked after commenting out the binding, and I don't know if there is something wrong with my code, but here is the code that generated the issue:

import customtkinter as ct
from customtkinter import *
from  CTkListbox import *

ct.set_appearance_mode("dark")
ct.set_default_color_theme("blue")

main_window=CTk()
main_window.geometry("600x400+250+200")
main_window.title("YouTube Videos Titles And Description")

firstList = CTkListbox(main_window,)
firstList.grid(row=0,column=0,padx=25,)


secondList = CTkListbox(main_window)
secondList.grid(row=0,column=1,padx=25,)


myIDs=range(20)


def getMyList():
    for id in myIDs:       
        firstList.insert("END",str(id)+" - list 1")
        secondList.insert("END",str(id)+" - list 2")
        secondList.update_idletasks()

getButton = CTkButton(main_window,text="Get The Titles & The Descriptions",
                      command=getMyList)
getButton.grid(row=1,column=1,padx=5,pady=10, sticky=E,)

main_window.mainloop()

Thanks again for the library, and for your time.

How to bind other events

I used a.binder("", lambda event:right_click(event, 0)) without any reaction
It would be perfect if you could bind events freely

Error when deleting all in empty listbox

If you try to delete an empty listbox using listbox.delete("all", tkinter.END) you get this error:
line 178, in deselect
if self.buttons[index] in self.selections:
~~~~~~~~~~~~^^^^^^^
KeyError: 0

tipp: in case you get the error (TypeError: 'float' object cannot be interpreted as an integer) when trying to delete the list objects

If there were too many file names/objects listed in the list box and I tried to delete the entire contents of the list using the command ".delete(1.0, tk.END)", I received the following error message:

for i in range(index, int(last)+1):
TypeError: 'float' object cannot be interpreted as an integer

and nothing was deleted.

If you have the problem, use the command:

".delete(0, self.file_listbox.size() - 1)"

or:

".delete("all")"

Height value ignored during ListBox creation

Hi! CTkListbox great tool!
Unfortunately I'm not able to adjust height, only width is changing.
I took care to install last available version but with not solving issue
Below simple code I use where "height" is ignored

txtRC=CTkListbox(tabview.tab(tabD4),width=445, height=50)
txtRC.place(x=10,y=200)

curselection issue

Great Listbox!
I've got a issue with the curselection in my project.
It is very simple, i want to select an item of the listbox and the selected item have to show in an entry digit.
But it doesen't work. How is the code, to get the value from the index?

My try:
index = list.curselection()[0]
value = list.get(index)

Highlight listbox item without selecting

Is there a method to highlight listbox items without using select?

Something like CTkListbox.highlight(index)

To clarify I'm basically looking for a method to highlight listbox items without calling any command that's assigned to the listbox.

Problem when deleting an option

When i delete an option and i click on the folowing options, the option after my selection is selected. So if i delete index 3 and then click on index 4, index 5 is selected.

BTW, thank you for your widgets. GOOD JOB !

import customtkinter
from CTkListbox import *

def show_value(selected_option):
    print(selected_option)
    
root = customtkinter.CTk()

listbox = CTkListbox(root, command=show_value)
listbox.pack(fill="both", expand=True, padx=10, pady=10)

listbox.insert(0, "Option 0")
listbox.insert(1, "Option 1")
listbox.insert(2, "Option 2")
listbox.insert(3, "Option 3")
listbox.insert(4, "Option 4")
listbox.insert(5, "Option 5")
listbox.insert(6, "Option 6")
listbox.insert(7, "Option 7")
listbox.insert("END", "Option 8")


def delete():
    listbox.delete(3)

button = customtkinter.CTkButton(root, text="Delete", command=delete)
button.pack(fill="both", expand=True, padx=10, pady=10)

root.mainloop()

.delete not working? Maybe?

Hey, I'm trying to delete all the data inside my listbox every time I search and add the new data that matches some characters (basically a search box). When I'm trying to delete the data I keep getting this error:

File "C:\Users\Mariusel\Desktop\New folder (2)\main.py", line 142, in
update_listbox(people_list_from_db)
File "C:\Users\Mariusel\Desktop\New folder (2)\main.py", line 137, in update_listbox
listbox.delete(customtkinter.END, 0)
TypeError: CTkListbox.delete() takes 2 positional arguments but 3 were given

This is my code:
def update_listbox(data):
# Sort the data alphabetically by the "nume" field
sorted_data = sorted(data, key=lambda x: x["nume"].lower())
listbox.delete(customtkinter.END, 0)
for person in sorted_data:
listbox.insert(customtkinter.END, person["nume"])

The code was working before and it was the same except the customtkinter.END syntax. Can I get some help with that?

Noticed a recursive call on listbox select

I've added this code to overcome it:

def on_listbox_select(self, selected_option):
    self.counter += 1
    self.index = self.listbox.curselection()
    if self.counter % 2 == 0:
        print("Counter = ",self.counter)
        self.add_index_to_selection(self.index)
    else:
        return

Found a wierd bug in the get() function

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

Issue with moving options up and down

Hi,

When moving options in a listbox up and down it seems to glitch out (I think its related to something in the insert method). The code below works in tkinter but not Ctk.

import customtkinter
from CTkListbox import *

def show_value(selected_option):
    print(selected_option)
    
root = customtkinter.CTk()


def moveup():
    try:
        idxs = tuple([animalBox.curselection()])
        if not idxs:
            return
        for pos in idxs:
            if pos==0:
                continue
            text=animalBox.get(pos)
            animalBox.delete(pos)
            animalBox.insert(pos-1, text)
            animalList.pop(pos)
            animalList.insert(pos-1, text)
        animalBox.select(pos-1)
    except:
        pass

animalList = ['Cat', 'Dog', 'Bear', 'Dolphin', 'Kangaroo']
animalString = customtkinter.StringVar(value=animalList)

animalBox = CTkListbox(root, command=show_value,listvariable=animalString)
animalBox.grid(row=1, column=0,padx=20, pady=10)



moveupButton = customtkinter.CTkButton(root,text="Move Up",command=moveup,width=200,height=35)
moveupButton.grid(row=2, column=0,padx=20, pady=10)

root.mainloop()

Build and publish the package

Hello, your project seems great!

But currently, because of the way we (e.i, us, developpers needing a CTkListbox) are supposed to install it, there are a some problem about managing dependencies.
For example, if you want to upgrade your package and then publish it, I would have to keep track about your change by hand, then remove the files in my project, and then re-install the updated version manually..

A great fix would be to build and publish it to PyPi using a tool like poetry. It is really easy to use and you could probably get the job done for you in a couple or commands (poetry init / poetry add customtkinter / poetry build / poetry publish).

Thanks.

listvariable error

There is no listrvariable in CTkListbox, when will you add this feature?

Errors when selecting new entry after clearing and reloading the CustomTKinter listbox

Hi,

I'm encountering tkinter errors when I use this customtkinter listbox and do the following:

I run program, select 1 or more entries. Then run a subroutine based on selected indexes. (This works fine)
Once the subroutine finishes, I execute a listbox.delete("all") to clear the list. then loop and insert new entries.

So far all looks good. New entries show.

But once I click on any entry I error with bottom one: "_tkinter.TclError: invalid command name ".!ctkframe2.!canvas.!ctklistbox.!ctkbutton"

Any insight? Is there something I'm missing to flush and reload the listbox?

Thanks

Sincerely

Radian327

Behaviour issues while getting selection callbacks

Hello! I've been using this addon alongside with CTK and i just stumbled apon some behaviour issues while trying to get callbacks when a list item is selected.

1 - While trying to bind a selection event ("listbox.bind("<>", callback)") it simply does not run.
2 - If i use the "command=" argument while declaring the listbox and point it to a function, i am able to get the selected item but only for the first time. After selecting an item for the second time the list refuses to visually change (and the selection actually remains stuck) and it only returns the last indexed item.

I did test the normal tkinter listbox and all is working as intended.

It could be incorrect implementation on my part, but some feedback on this would be aprecciated!

scroll bar alignment issue

I don't have an easy way to test across OS's but at least for me on windows the scroll bar is aligned a few pixels too far right and covers the border slightly. Tested across 3 windows installs and all have the same alignment issue. It's easy enough to adjust in the class but I'm hesitant to send a pull request as this could be something on my end or intentional style choice.

Example: https://imgur.com/a/U7HdiOg

A simple offset works but should probably be based on the scroll bar width:

self._scrollbar.grid_configure(padx=(0,border_width + 4))
self._scrollbar.configure(width=12)

Example:

scroll_bar_width = 12
scroll_bar_offset = (border_width + scroll_bar_width) - 8  # 8 is whatever the default border offset would be
self._scrollbar.grid_configure(padx=(0, scroll_bar_offset))
self._scrollbar.configure(width=scroll_bar_width)

Option to fit height to contents

Feature request.
It would be nice to have a feature that fits the box to the height of the contents, as well as having a max height before you have to scroll

Listbox not allowing additional items.

Hi @Akascape ,

As usual, thank you for the great addition to customtkinter. I recently ran into a very strange issue.

I have a listbox that stores a number of curves that can be added to a graph.
image

In order to import new curves I have a dialog box with a listbox in it.
image

Once the number of imported curves no longer fits in the original listbox (in my case its 6 items) it will no longer allow items to be added to it.
image

I can also delete curve three for instance and it will populate one of the previously hidden items
image

This then affects any other listboxes that I have. If a listbox previously scrolled it still does after this occurs, but it also stops showing any items that are added afterwards.

Edit: I should note that I don't get any errors from this.

Add parameters to style buttons

Perhaps add a button_fg_color or allow passthrough of all CTkButton parameters to the constructor so that list items can be styled. Currently it looks very weird on light mode. Right now it's forced to be transparent, which leaves the only option as bg_color, which doesn't have the rounded corners. if you use the bg_corners_colors tuple list, there is some artifacting, so that's not a workaround currently

Additions would probably be on line 40:

        self.button_fg_color = "transparent" if button_fg_color=="default" else button_fg_color

and added to line 147:

        self.buttons[index] = customtkinter.CTkButton(self, text=option, fg_color=self.button_fg_color, anchor=self.justify,
                                                      text_color=self.text_color, font=self.font,
                                                      hover_color=self.hover_color, **args)

Thanks!

Why is it so slow?

Hello, i would like to know why CTkListbox is really slow, at least for me. When adding items in it using insert method, it takes in average 0.02 seconds, it's noticeable. It also updates itself in runtime every time you insert. Adding items in tk.Listbox is mutch faster, it takes about 6e-6 seconds and it doesn't update itself. I think CTkListbox is slow because it updates itself, but I don't need that, I want to insert a bunch of items and then display them. How can I deal with this?

Thanks for your library and your time.
Sorry, if I am doing something wrong, it's my first time creating an issue.

I can't create CTkListbox with height less than 200

If you explicitly specify a height less than 200, it will still be created with a minimum value of 200

ist_box = CTkListbox('some parent', width=100, height=100)
list_box.place(anchor=CENTER, relx=.80, rely=.50)

Issues updating the value list.

Heya, I am having quite an odd bug with the list box.

I know it is probably not your doing and it is just me being dumb but when using a function to update the list box, it causes it to not update but just stay as it is. The odd thing is, I can call a variable that is meant to be there and it tells me that it is there and fine.

The code is quite simple as of now but here is the part where it should be doing it.

def add_url(self, addurl):
    print("add function called")
    print(addurl)
    self.URLlist.insert("end", str(addurl))
    self.URLlist.after(10, self.update_list)  # Force an update of the listbox
    print("added url")
    testprint = self.URLlist.get(2)
    print("the third item isx",testprint)

def update_list(self):
    print("list update called")
    self.URLlist.update()
    self.URLlist.update_idletasks()
    print("list update complete")

This is the output I get in a terminal

add function called
test
added url
the third item is test
list update called
list update complete

But then this is what I see inside the app.

image

I find it quite odd that it can add the item, see the item on a base level but can't display it in the list. If ya got any suggestions, feel free to shoot them my way!

Thanks for reading this if you do <3

Add support for custom themes

Customtkinter supports creating own themes, so that the styling does not need to be set manually.

Consider adding support for a CTkListbox item in the theme.json file:

If customtkinter.ThemeManager.theme["CTkListbox"] exists, use the colors defined in the theme, otherwise the default ones.

issue with deleting items

Hello, nice project really love it, but i have issu with deleting last item from listbox, can you help me?

import customtkinter as ctk
from CTkListbox import *

def insrt():
listbox.insert('END', 0)
print(listbox.size())

def delt():
listbox.delete('END')

root = ctk.CTk()
listbox = CTkListbox(root, width=80, height=60)
listbox.pack(fill="both", expand=False, padx=2, pady=10, side="left")
btn4 = ctk.CTkButton(root, text="in", command=insrt)
btn4.pack(side="left", padx=30, pady=15)
btn5 = ctk.CTkButton(root, text="out", command=delt)
btn5.pack(side="left", padx=30, pady=15)
root.mainloop()

Issue between CTkListbox super().bind_all and tk bbox call

Hej!!

I have updated the CTkListbox and I am getting this error:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\tsouzada\AppData\Local\Programs\Python\Python39\lib\tkinter_init_.py", line 1892, in call
return self.func(*args)
File "C:\Users\tsouzada\AppData\Local\Programs\Python\Python39\lib\site-packages\CTkListbox\ctk_listbox.py", line 115, in
super().bind_all(key, lambda e: func(self.get()), add="+")
File "C:\Users\tsouzada\AppData\Local\Programs\Python\Python39\lib\site-packages\customtkinter\windows\widgets\ctk_scrollable_frame.py", line 75, in
self.bind("", lambda e: self._parent_canvas.configure(scrollregion=self.parent_canvas.bbox("all")))
File "C:\Users\tsouzada\AppData\Local\Programs\Python\Python39\lib\tkinter_init
.py", line 2731, in bbox
self.tk.call((self._w, 'bbox') + args)) or None
_tkinter.TclError: invalid command name ".!ctktabview.!ctkframe.!tab_environment.!ctkframe.!sidebar_environment.!ctkframe.!ctkframe.!canvas"

And I saw there was an update kind of related to that (991da89)
Have you seen this kind of issue or do you have an idea what it could be about?
This error happens when closing the CTk window

CTkListbox 0.7
customtkinter 5.2.0

Support for exportselection=False/True

Hello,

Appreciate the work for this addition to customtkinter, I currently have a listbox inside of a tabview and when I tab back and forth it unhighlights the listbox selection.

Could exportselection be added as an option for CTkListbox?

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

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

Bug when I want to remove an option from the list

When i use the listbox.delete(index)
it leaves me with an error keyerror: and the index I'm trying to delete

this my code

`def ModifyDataWindow(button_name):
window = ctk.CTkToplevel()
window.geometry("400x600")
window.title("Add data")
font = ctk.CTkFont("Arial", 30)

label = ctk.CTkLabel(window, text=f"Modify {button_name} data", font=font)
label.pack(padx=20, pady=20)

data = read_values_from_json(FILE_PATH, button_name)

def show_value(selected_option):
    print(selected_option)

def remove_selection():
    selected_indices = listbox.curselection()
    for index in reversed(selected_indices):
        listbox.delete(index + 1)

listbox = CTkListbox(window, command=show_value, multiple_selection=True)
listbox.pack(fill="both", expand=True, padx=10, pady=10)

for item in data:
    listbox.insert(ctk.END, item)

removebutton = ctk.CTkButton(window, text="Remove", command=remove_selection)
removebutton.pack(padx=20, pady=20)`

Thank you for your help

Select function broke after last update

Got this error after the last update when trying to click on items in my listbox which is popualated with basic string references to .txt files. Neither .activate() or regular select works.

C:\noyb\projects\studd\lists<VirtualEvent event x=0 y=0>.txt Sort
File not found: C:\noyb\projects\studd\lists<VirtualEvent event x=0 y=0>.txt
Error opening file: [Errno 22] Invalid argument: 'C:\noyb\projects\studd\lists\.txt'

self.listbox = EditorListbox(self.bottom_frame, command=self.on_listbox_select)

class EditorListbox(CTkListbox):
def init(self, master, command=None, **kwargs)

    self.command = command
    
    self.bind("<<ListboxSelect>>", self.on_listbox_select)

def unbind(self):
    self.unbind_all("<<ListboxSelect>>")

def update_theme(self):
    self.configure(
        fg_color=listbox_fg_color, 
        highlight_color=listbox_select_color,  
        border_color=listbox_border_color, 
        hover_color=listbox_select_color,
        text_color = listbox_txt_color,
        scrollbar_button_color=scrollbar_color,
        scrollbar_button_hover_color=scrollbar_hover_color
    )

def on_listbox_select(self, event):
    if self.command:
        self.command(event)

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.