Change Tkinter Background color when a function runs

Viewed 378

I'm trying to change the background color of tkinter when a particular function runs.

Problem i'm facing is the background color doesnt change until after the function finishes

Is there a better way to do this?

End results will have more methods when each method is called it should change the background color.

class Test:

    window = Tk()
   

    def TT():
      Test.window.configure(background='red')
      tester_function()
      
      

    def GUI(self):  
        Button(Test.window , text="ON",width=6, command=Test.TT).grid(row=0,column=0, sticky=W)
        Test.window.configure(background='black')
        Test.window.mainloop()

    
    


Test().GUI()
1 Answers

Try adding this line after you change the background color :

Test.window.update()

This will effectivily refresh the window thus changing the background color.

Related