Reputation: 99
I've made a pygame GUI interface with buttons who are activated when the user click on them. The GUI works well when I'm using my real mouse but when I run the GUI on the PITFT, buttons don't respond to clicks ( even if I use a harder material than my finger like a stylus ).
Are Pygame click event compatible with the PITFT or are there a kind of "special" event made for it?
Here is the current mouse event I use in my code:
def run(self):
"""Lance la boucle principale pour gérer les événements"""
while True:
event = pygame.event.wait()
if event.type == MOUSEBUTTONDOWN and event.button == 1 and not self.keep_level_2:
self.click(event.pos)
elif event.type == MOUSEBUTTONUP and event.button == 1:
self.release(event.pos)
I search on the internet and found that in order to use the PITFT, you need to add the following lines:
os.environ['SDL_VIDEODRIVER'] = 'fbcon'
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
So I've tried adding them but the touchscreen is still not responding.
Also, when to program run, I can't quit it ( CTRL+C and escape don't work ).
Note: My code is not running in python3.
Upvotes: 1
Views: 7871
Reputation: 633
Did you check that your /dev/input/touchscreen is "linked" to the right module? Check evtest /dev/input/touchscreen and check if it does anything when using the screen, or the keyboard, or the mouse!
If this is happening you should follow the install procedure again.
Upvotes: 0
Reputation: 1
I think what's happening is you're doing a button up, button down methond.
I get my pygame GUI to work by going...
click = pygame.mouse.get_pressed()
if x+w > mouse_pos[0] > x and y+h > mouse_pos[1] > y:
pygame.draw.rect(screen, ac,(x,y,w,h))
if click[0] == 1 and action != None:
action()
HOWEVER for me this creates other issues because I don't think that 1 tap on the touch screen is a SMOOTH single click. What happens for me is that my button will click, then it will for no apparent reason do a second 'click' (I think because of 'fuzz' in the click).
As a result, my 'on' buttons turn on (they work perfectly) and then they turn off. Not quite sure what to do about that yet, but hopefully it gets your project working.
Upvotes: 0