As suggested by @TheLizzard, I changed update_idletasks() for update()and it works.
update_idletasks()
update()
There seems to be a problem on Windows because @TheLizzard tested the original code on Ubuntu and it worked.