CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

custom tkinter combobox command not working as the tkinter postcommand parameter

Open bonifacefernati opened this issue 10 months ago • 0 comments

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 ?

bonifacefernati avatar Dec 22 '24 22:12 bonifacefernati