-3

I'm trying to make gui with tkinter (I also use customtkinter to have a good design) and I'm trying to make categories, I created for this a margin (with a frame) in which I have place buttons for the different categories, I would like the button of the current category to be colored blue, and the other buttons to be gray, so I wrote the code for this but the expected effect does not happen, the problem is that the last button of the dictionary turns blue (and the rest) and that even if I don't press this one but another one, can you help me please? here is my code

class App(customtkinter.CTk):

    def __init__(self):
        super().__init__()

        self.WIDTH = 780
        self.HEIGHT = 520
        self.nom_window='Opticopilot 1.0'

        self.geometry(str(self.WIDTH)+'x'+str(self.HEIGHT))
        self.title(self.nom_window)
        self.configure(bg='#333333')
        #self.columnconfigure(0, weight=1)
        #self.rowconfigure(0, weight=1)

        

        self.frame_gauche=customtkinter.CTkFrame(master=self,width=(self.winfo_screenwidth()//13),height=self.winfo_screenheight(),corner_radius=0)
        self.frame_gauche.grid(row=1, column=0,sticky='w',rowspan=15, columnspan=2)

        self.frame_gauche.grid_propagate(0)
        #self.frame_gauche.winfo_screenwidth() 

        self.dictionnaire_bouttons_marge_gauche={}

        self.dictionnaire_bouttons_marge_gauche["P.E.C"]= customtkinter.CTkButton(master=self.frame_gauche,width=(self.frame_gauche.winfo_screenwidth()//13),height=(self.frame_gauche.winfo_screenheight()//25),border_width=0,corner_radius=0,text="P.E.C", fg_color='grey')
        self.dictionnaire_bouttons_marge_gauche["P.E.C"].grid(row=0, column=0)
        
        self.dictionnaire_bouttons_marge_gauche["Notifications"]= customtkinter.CTkButton(master=self.frame_gauche,width=(self.frame_gauche.winfo_screenwidth()//13),height=(self.frame_gauche.winfo_screenheight()//25),border_width=0,corner_radius=0,text="Notifications", fg_color='grey')
        self.dictionnaire_bouttons_marge_gauche["Notifications"].grid(row=2, column=0)


        self.dictionnaire_bouttons_marge_gauche["Facturation"]= customtkinter.CTkButton(master=self.frame_gauche,width=(self.frame_gauche.winfo_screenwidth()//13),height=(self.frame_gauche.winfo_screenheight()//25),border_width=0,corner_radius=0,text="Facturation", fg_color='grey')
        self.dictionnaire_bouttons_marge_gauche["Facturation"].grid(row=1, column=0)



        def effet_boutton_selectionne(dictionnaire,key): 

            for clee in dictionnaire:

                if clee!=key:
                    dictionnaire[clee].configure(fg_color='grey')

                else:
                    dictionnaire[clee].configure(fg_color='blue')

                    

            


        """self.dictionnaire_bouttons_marge_gauche["P.E.C"].configure(command=lambda:effet_boutton_selectionne(self.dictionnaire_bouttons_marge_gauche,self.dictionnaire_bouttons_marge_gauche["P.E.C"]))
        self.dictionnaire_bouttons_marge_gauche["Facturation"].configure(command=lambda:effet_boutton_selectionne(self.dictionnaire_bouttons_marge_gauche,self.dictionnaire_bouttons_marge_gauche["Facturation"]))
        self.dictionnaire_bouttons_marge_gauche["Notifications"].configure(command=lambda:effet_boutton_selectionne(self.dictionnaire_bouttons_marge_gauche,self.dictionnaire_bouttons_marge_gauche["Notifications"]))"""


        for boutton in self.dictionnaire_bouttons_marge_gauche:

            self.dictionnaire_bouttons_marge_gauche[boutton].configure(command=lambda:effet_boutton_selectionne(self.dictionnaire_bouttons_marge_gauche,boutton))


        







I tried the code above but without success, I tried different methods of configuring the code, without success either

AcK
  • 2,063
  • 2
  • 20
  • 27
Jaden
  • 1
  • 1
  • 1
    If [my answer](https://stackoverflow.com/a/74554545/20585541) was helpful, please mark it as the answer to your question by clicking the checkmark below the up and downvote buttons. Thanks! – Ben the Coder Jun 30 '23 at 20:23

1 Answers1

-1

Try looking at the tkinter documentation for coloring GUI elements.

In short, to color a GUI label, use the following code:

l1 = tkinter.Label(text="Test", fg="black", bg="white")
Ben the Coder
  • 539
  • 2
  • 5
  • 21