# Using for loop to move a container

**URL:** <https://forum.inductiveautomation.com/t/using-for-loop-to-move-a-container/4924>\
**Category:** Ignition\
**Created:** [August 3, 2012, 6:02pm UTC](https://forum.inductiveautomation.com/t/using-for-loop-to-move-a-container/4924 "2012-08-03T18:02:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkrugerud](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jkrugerud](https://forum.inductiveautomation.com/u/jkrugerud)\
**Post date:** [August 3, 2012, 6:02pm UTC](https://forum.inductiveautomation.com/t/using-for-loop-to-move-a-container/4924/1 "2012-08-03T18:02:10Z")

</div>

I have been having issues using a timer to move a container up and down not by just appearing at its new location but moving into place at a certain rate during the mouseEntered event so I went with a for loop as shown:

import time  
y = 297

for y in range(107,197):  
system.gui.moveComponent(event.source, 196, y)  
y = y - 1  
time.sleep(1)  
if y == 107:  
break

This doesn’t work for me either even though it seems like it should, what it does is pause a second before moving the container to the final position of (196,107). Do you know why that is? Do you have a better method of doing this?

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [August 3, 2012, 6:39pm UTC](https://forum.inductiveautomation.com/t/using-for-loop-to-move-a-container/4924/2 "2012-08-03T18:39:36Z")

</div>

Your range starts at 107, so the second iteration y is 108 and the conditional for breaking the loop is met.

Seems like you’d be able to simplify that a bit too…

```auto
import time
y = 297 # why is this declared up here? is this used elsewhere?
x = 196

# get your range and reverse it
range_of_movement = range(107,197)
range_of_movement.reverse()

# move through each value in the range
for y in range_of_movement:
	system.gui.moveComponent(event.source, x, y)
	time.sleep(1)	
```

---

<div class="post-metadata">

**Author:** ![jkrugerud](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jkrugerud](https://forum.inductiveautomation.com/u/jkrugerud)\
**Post date:** [August 3, 2012, 6:56pm UTC](https://forum.inductiveautomation.com/t/using-for-loop-to-move-a-container/4924/3 "2012-08-03T18:56:16Z")

</div>

I tried this but my loop froze

---

<div class="post-metadata">

**Author:** ![Michael.Stofan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.stofan/32/3342_2.png) [@Michael.Stofan](https://forum.inductiveautomation.com/u/Michael.Stofan)\
**Post date:** [August 3, 2012, 11:41pm UTC](https://forum.inductiveautomation.com/t/using-for-loop-to-move-a-container/4924/4 "2012-08-03T23:41:52Z")

</div>

The event script is running on the same thread as the GUI. So when you call time.sleep(), it’s actually preventing the screen from being repainted.

What I would recommend is instead using a timer component with a property change event handler on it. Then, every time the timers property changes, it moves the proper component a certain number of pixels using system.gui.moveComponent(). This continues until the component has been gradually moved to the new position.

Hope that made sense…
