Austen Vigneux
Austen Vigneux

Reputation: 33

How do I use multi touch in a Python paint program?

I'm building a simple paint program in Python as a project, using Pygame it works by basically drawing a stream of circles when the mouse gets pressed and you drag it around the surface, it's got a couple other little things going on but the thing I want to ask is, is there a way to change the singular mouse input you know mouse.get_pressed to either multiple mouse inputs at one time or a multi-touch input into the point list that's streaming the circles.

running= True

while running:

if buttons[0] == True:
    x,y = pygame.mouse.get_pos()

    if x> PA+AS:
        xShift = x - PA - AS
        pygame.draw.circle(pArea,DRAW_CLR,(xShift,y),BRUSHSIZE)
        pygame.display.flip()

so this is the part of the code I really want to change more or less. Just so that instead of just one mouse, I could use my touchscreen to draw with maybe two finger.

Upvotes: 2

Views: 2057

Answers (2)

Vincenzooo
Vincenzooo

Reputation: 2401

Latest versions of pygame support multitouch input (and I believe also gestures).

The events which control it are pygame.FINGERDOWN, .FINGERUP and .FINGERMOTION. My understanding is that they work like mouse inputs, but can be multiple and can be distinguished by means of an event.finger_id property.

An example can be found here: https://www.patreon.com/posts/finger-painting-43786073?l=fr

Upvotes: 2

spirulence
spirulence

Reputation: 721

You're going to have a difficult time if you insist on doing this in PyGame. Your best bet for multitouch in Python is Kivy, which was a very solid framework a few years ago when I used it and appears to have only gotten better since.

The disadvantage of switching to Kivy is a more complicated API, but this tutorial seems spot-on for what you're trying to do.

Upvotes: 0

Related Questions