Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTkListbox 'font' parameter not working #71

Open
ItsMichaelll opened this issue Aug 7, 2024 · 1 comment
Open

CTkListbox 'font' parameter not working #71

ItsMichaelll opened this issue Aug 7, 2024 · 1 comment

Comments

@ItsMichaelll
Copy link

I wanted to change the font of the buttons inserted into the CTkListbox, so I used the 'font' parameter, but it wasn't changing the font of the buttons.

Here's my initialization of the CTkListbox:

list = CTkListbox(
    master=self.frame1,
    height=200,
    text_color=['#000, #FFF'],
    font=("Proxima Nova Rg", 18, "bold"), # this wasn't doing anything
    hover_color='#00458A',
    highlight_color='#0267c9',
    multiple_selection=True,
)

I discovered a temporary fix for myself by modifying your ctk_listbox.py file, particularly the 'insert' method in line 198.
I did have to add the import line import ast to the top of your ctk_listbox.py file for my fix, though.

'ctk_listbox.py' (line 198):

    def insert(self, index, option, update=True, **args):
        """add new option in the listbox"""

        if str(index).lower() == "end":
            index = f"END{self.end_num}"
            self.end_num += 1

        if index in self.buttons:
            self.buttons[index].destroy()

        font = ast.literal_eval(self.font.cget('family'))    # i added this
        
        self.buttons[index] = customtkinter.CTkButton(
            self,
            text=option,
            fg_color=self.button_fg_color,
            anchor=self.justify,
            text_color=self.text_color,
            font=font,    # i changed this from 'font=self.font' to 'font=font'
            hover_color=self.hover_color,
            **args,
        )
        # the rest of the method stays the same

I'm hoping there is a better fix for this? Let me know, and if you're having trouble reproducing it I can provide more of my code.

@gioradicci
Copy link

It doesn't work instancing the class with font parameter, but it works if assigned after with the font property :
Example:
`
custom_font =("Arial",11)
self.listBoxAnnoTarget = CTkListbox(self.targetoptselection_frame, multiple_selection=False, command=self.filter_ui, font=custom_font) #NO CHANGE

self.listBoxAnnoTarget = CTkListbox(self.targetoptselection_frame, multiple_selection=False, command=self.filter_ui)
self.listBoxAnnoTarget.font=custom_font #THIS WORKS
`
This is the workaround I used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants