[solved] Slider and touch screen
Hi everyone
I currently try to make a slider work with a touch screen. I have found a lot of ideas in this forum, only one misses me.
I want to save the slider position by the click on a button below the slider. My problem is to close the loop of the slider when the mouse (or the finger) is outside the slider.
If anyone has this idea, or the solution (even better), I would be very interested.
Thanks
Tom
Comments
Hi Tom,
I'm guessing you use the code from this post:
Is that right?
To do this, you need to
breakthewhileloop when the coordinates of the mouse are outside of the slider boundaries. For example like so (this checks only the vertical position):In the context of the entire script that would look something like this:
Does that help at all?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
thank you for your answer. Yes, this is the script I try to use, and yes also, this is the idea.
If I understand well, the break you add "breaks" completely the loop, ie with a mouse, as soon as you move, you switch to the next slide and saving the position.
My idea was a loop in which you could come and go on the slider both with finger or mouse and then validate with a button outside the slider, thefore put the mouse clic within the button and not on the while loop of the slider. Am I clear enough?
I'm sorry to be so poor with python but I'm working on it
I had yesterday a seminar with Lotje van der Linden, after sending my question on this forum, and she also agree to help me (a little) in case you don't have much time...
Best
Tom
and thanks again for this help!
Hi Tom,
If I understand correctly, it should be enough if nest the slider
whileloop into anotherwhileloop that waits for a mouse/finger click on the button. So, you have to rewrite Sebastiaan's code somehow like this:Is this what you meant?
Best,
Eduard
Hi
Thank you very much for your time and valuable help.
The loop inside the loop was exactly what I was trying to do.
I tested you script and it works perfectly on desktop but not on the Surface pro I use for experiment. It gives an error on the slider_fill variable not declared. any idea? (same installation, same version and all)
And by the way, I do not want to abuse, but how can I dissociate the slider movement (one loop) and the click in a "validate" separate button on the screen (second loop).
As this is for children, I prefere that no ambiguity remains.
I suppose I should change the last part of the loop saying button != none to include it in a rectangle canvas?
Thanks again
Best
Tom
HI,
I don't understand why this works on one version, but not on the other. Anyway, I suppose the error arises, if the inner
whileloop is not entered, becauseslider_fillis only defined there. A solution can be initializingslider_fillearlier one, even before the outerwhileloop is entered, to 0, or some sensible starting value.I'm not sure whether I understand your second request right, but if you want to separate the loops, you can do so rather easily, you just have to watch out, that all the variables belonging to one of the operations are also going there. Then, you can start the script with a single conditional that defines which
whileloop is entered,e.g.if pos=='coordinates_of_button: enter_button = True, else: enter_button = Falseand accordingly for the slider. Later you just check whetherenter_sliderorenter_buttonand enter where you wanna go.Does this help?
Eduard
Hi

thanks, I begin to understand the logic of Python (more used to vb in eprime). I will try with the idea you gave by enter a similar loop as the slider loop when the mouse is outside the slider but goes into a button.
the - if button != None: break - should be then is this loop so no more clicking by mistake.
the result should be something like this
Thanks
And yes this does help!
tom