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

custom tkinter combobox command not working as the tkinter postcommand parameter #2666

Open
bonifacefernati opened this issue Dec 22, 2024 · 0 comments

Comments

@bonifacefernati
Copy link

bonifacefernati commented Dec 22, 2024

the postcommand parameter of the combobox in tkinter allows with a function to update the values ​​of the combobox when they have been modified for example in a toplevel secondary window.
the same function called by the command parameter of the custom tkinter combobox does not allow this in the same way.

even using the configure method
example:

self.company = customtkinter.CTkComboBox(self.frame, font=("Arial", 12, "bold"), text_color='#000', fg_color='#fff',
button_color='#7F7F7F',
border_color='#7F7F7F', border_width=1,
dropdown_fg_color= '#fff', dropdown_text_color='#000',dropdown_font=("Arial", 12,
"bold"),dropdown_hover_color='#7F7F7F',
hover=False, bg_color='#594C59',
state= 'readonly', width=500, values=self.liste_companies , command=self.upd_list_companies1,
corner_radius=8)

def upd_list_companies1(self, value):
    liste_companies_new = ListerCompanies().liste_companies
    options = liste_companies_new
    self.company.configure(values=options)
    if value == ' __update values__':
        self.company.set('Values updated, Clic Again -->')
    else:
        self.company.set(value)
    del liste_companies_new

For this function to be called you must click on the combobox button and then click on an item of the values -> 2 clics

trying to call the update values ​​function right after calling the secondary window doesn't work either. you get an error message as if the combobox's dropdown list no longer exists at that moment

it is not professional for the user.

at the moment I have to use a horrible workaround with an update values line to get around this problem

While with the postcommand parameter of the classic combobox of tkinter at the first click on the button of the combobox the list of values ​​was updated. It worked perfectly.

Could you help ?

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

1 participant