I'm building a GUI in Python (3.11) and tkinter on a Windows 10 PC with a touchscreen. The GUI controls a camera which should zoom in while a button is pressed. Binding a ButtonPress and ButtonRelease event to the widget works perfectly with a normal mouse, but doesn't work when using a touchscreen.
Windows normally uses press-and-hold on a touchscreen to simulate right-click. You can disable this functionality through: Control Panel->Pen and Touch->Press and hold->Settings... ; or through: Registry: \HKCU\SOFTWARE\Microsoft\Wisp\Touch->TouchMode_hold (0).
However, when using the code below with above settings on a touchscreen the ButtonPress event is not triggered when the button is pressed and held, but is triggered only when the button is released. The ButtonPress and ButtonRelease event are triggered right after each other. The ButtonPress event also triggers when the button is held and you move/swipe on the screen.
With this minimal code example the problem can be reproduced.
import tkinter as tk
def start_zoom(event):
print(f'{event}')
def stop_zoom(event):
print(f'{event}')
root = tk.Tk()
label = tk.Label(root, text='Zoom in', width=50, height=20)
label.bind('<ButtonPress-1>', start_zoom)
label.bind('<ButtonRelease-1>', stop_zoom)
label.pack()
root.mainloop()
Instead of two functions - start and stop, you can use
repeatdelayandrepeatintervalwith single function zoom()