Using for loop to move a container

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
if y == 107:

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?

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…

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)

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

I tried this but my loop froze

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…