Skip to content

Instantly share code, notes, and snippets.

@iz4blue
Created September 22, 2015 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iz4blue/0669177d870552faee7d to your computer and use it in GitHub Desktop.
Save iz4blue/0669177d870552faee7d to your computer and use it in GitHub Desktop.
RaspberryPi touch screen get pos
File Edit Options Buffers Tools Python Help
# -*- coding:utf-8 -*-
import pygame
import sys
import os.path
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
GRAY = (126, 126, 126)
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 1024
def Main():
pygame.init()
SCREEN_WIDTH = pygame.display.Info().current_w
SCREEN_HEIGHT = pygame.display.Info().current_h
print "%d x %d" % (SCREEN_WIDTH, SCREEN_HEIGHT)
size = (SCREEN_WIDTH, SCREEN_HEIGHT)
screen = pygame.display.set_mode(size)
pygame.mouse.set_visible(True)
font_big = pygame.font.Font(None, 50)
screen.fill(BLACK)
while True:
for event in pygame.event.get():
if (event.type is pygame.MOUSEBUTTONDOWN) or (event.type is pygame.MOUSEBUTTONUP):
pos = pygame.mouse.get_pos()
print pos
text_pos = font_big.render(("%d x %d" % pos), True, WHITE)
pygame.draw.rect(screen, BLACK, [100, 100, 200, 200])
screen.blit(text_pos, (100,100))
pygame.display.flip()
if (event.type is pygame.KEYDOWN):
if event.key == K_ESCAPE:
sys.exit()
pygame.display.update()
Main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment