I am making a kiosk app for a raspberry pi in python with a 7 inch touchscreen. Everything works well and now, I am trying to make the scroll works like it does on touchscreens. I know that raspbian haven't got a properly touch interface, so, every touch on the screen work as a mouse-click, and if I move my finger touching the screen, works like the drag function.
To make this on python I use my modified version code of this Vertical Scrolled Frame using canvas and I need to add events binding <ButtonPress-1>
and <B1-Motion>
.
<ButtonPress-1>
might save the y position of the click and enable the bind_all
function for <B1-Motion>
.
<B1-Motion>
might set the scroll setting up or down the differrence between the y value saved by <ButtonPress-1>
and the event.y
of this event.
<ButtonRelease-1>
might disable the bind_all
function with <unbind_all>
of the scroll.
My added code of the events is this, but I don't know how to make it work properly the .yview
function of the canvas to make my function works as desired.
def moving(event):
#In this part I don't know how to make my effect
self.canvas.yview('scroll',event.y,"units")
def clicked(event):
global initialy
initialy = event.y
self.canvas.bind_all('<B1-Motion>', moving)
def released(event):
self.canvas.unbind_all('<B1-Motion>')
self.canvas.bind_all('<ButtonPress-1>',clicked)
self.canvas.bind_all('<ButtonRelease-1>', released)