TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
11.63k stars 1.09k forks source link

#deselecting all checked CTkCheckboxes #2630

Open coldsober-irene opened 3 weeks ago

coldsober-irene commented 3 weeks ago

how can I deselect all checked checkboxes?

teijiIshida commented 3 weeks ago

Use a for-loop. Loop through all your checkboxes and call deselect().

MaxNiark commented 2 weeks ago
        for i,v in enumerate(self.db_lic_sql_dict):
            command_1=partial(self._select_all_lic,self.db_lic_sql_dict[v])
            row_id+=1
            label=CTkLabel(self.lic_frame, text=v).grid(row=row_id)
            self.select_all=CTkCheckBox(self.lic_frame,text="all",command=command_1,textvariable="on")
            self.select_all.grid(row=row_id,column=1, pady=10)
            row_id+=1
            for j in self.db_lic_sql_dict[v]:
                lic,comment=j.split(";")
                self._checkbox_dict[lic]=CTkCheckBox(self.lic_frame,text=lic,command=lambda bouh=lic:self.radiobutton_event(bouh),)
                row_id+=1
                self._checkbox_dict[lic].grid(row=row_id,column=0,sticky="nw",pady=5)
    def _select_all_lic(self,db_sql, port=None):

        if self.select_all.cget("textvariable")=="on":
                        self.list_lic_select.clear()
                        for key in db_sql:
                            key_tmp,z=key.split(";")
                            str_port,str_lic= key_tmp.split("@")
                            if str_port == port :
                                self.list_lic_select.append([str_lic,str_port])
                                self._checkbox_dict[key].select()
                            if port == None:
                                self.list_lic_select.append([str_lic,str_port])
                                self._checkbox_dict[key_tmp].select()
                        self.select_all.configure(textvariable="off")
                        print("SELECTED ---- :",db_sql,'\n')

        elif self.select_all.cget("textvariable")=="off":          
                        for key in db_sql:
                            key_tmp,z=key.split(";")
                            str_port,str_lic= key_tmp.split("@")
                            self.list_lic_select.clear()
                            self._checkbox_dict[key_tmp].deselect()
                        self.select_all.configure(textvariable="on")
                        print("UNSELECTED ---- :",db_sql,'\n')
        print(self.list_lic_select)