Python Tkinter canvas update -


i want update color of circle in tkinter in python 2. can make circle color not update in task() method until stop running program. how can make color update val greater 4?

from tkinter import * m = tk() w = canvas(m, width = 100, height = 100) w.pack() cir = w.create_oval(50, 50, 100, 100)  def task():     while true:         val += 1         if val > 4:             w.itemconfig(cir, fill = "blue")  m.after(2000, task) m.mainloop() 

this work.

like @tigerhawkt3 said need break exit loop.

from tkinter import * m = tk() w = canvas(m, width = 100, height = 100) w.pack() cir = w.create_oval(50, 50, 100, 100)  def task():     val = 1     while true:         val += 1         if val > 4:             w.itemconfig(cir, fill = "blue")              #without break task run forever             break  m.after(2000, task) m.mainloop() 

Comments