Home > Enterprise >  How can I check if a button image is a certain image in tkinter
How can I check if a button image is a certain image in tkinter

Time:05-21

Ok so I want when I click an image button it runs a function and check if the button image is let's say equal to "img1"

Buton code

b1 = Button(root, image= img1, bd=0, bg='#292424', activebackground='#292424', command=lambda:press(b1))

CodePudding user response:

why not made a function with a variable. After the first click the variable equal 1 and the second click the variable equals 0 ?

I use this for my toggle button

edit :

self.intervention_conciliation = tk.Button(frame_1, text="Non", command=self.clic_boutton_conciliation)
    def clic_boutton_conciliation(self):
            # on va changer la couleur du bouton ainsi que l'inscription
            if self.intervention_conciliation["bg"] == "SystemButtonFace":
                self.intervention_conciliation["bg"] = "dim gray"
                self.intervention_conciliation["text"] = "Oui"
            else:
                self.intervention_conciliation["bg"] = "SystemButtonFace"
                self.intervention_conciliation["text"] = "Non"

Have a nice day

  • Related