How To Change Bg Color Of Button After Pressing And Get Back To Previous Color
In the below program i want to change the background color of the button to green after pressing it and changed color should remain for 2seconds and later change back to original c
Solution 1:
You can use the after
method to schedule a function to run after a pre-defined amount of time. You can use the configure
method to change a widget option. Put those two together and you have something like this:
def trial(self):
self.buttonA.configure(background="green")
self.after(2000, lambda: self.buttonA.configure(background="black")
Solution 2:
it works fine if i put code like:
def trial(self):
self.buttonA.configure(background="green")
self.after(10, lambda: self.buttonA.configure(background="black")
self.after(2000, lambda: self.buttonA.configure(background="green")
But am not sure whether its correct way or not
Post a Comment for "How To Change Bg Color Of Button After Pressing And Get Back To Previous Color"