How to use the pygame.display function in pygame

To help you get started, we’ve selected a few pygame examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sparkslabs / kamaelia / Sketches / JL / pygame / keyboardinput.py View on Github external
# See the License for the specific language governing permissions and
# limitations under the License.

import pygame
from pygame.locals import *
import string

screen_width=400
screen_height=300
tabs_height = 100
text_height=18
background_color = (255,255,255)
text_color=(0,0,0)
        
pygame.init()
screen = pygame.display.set_mode((screen_width, screen_height))
screenRect = screen.get_rect()
screen.fill(background_color)

scratch = screen.copy()
font = pygame.font.Font(None, 14)
linelen = screen_width/font.size('a')[0]
keepRect = pygame.Rect((0, text_height), (screen_width, screen_width-text_height))
scrollingRect = pygame.Rect((0, 0), (screen_width, screen_height - text_height))
writeRect = pygame.Rect((0, screen_height-text_height), (screen_width, text_height))

def setText(text):
    screen.fill(background_color)
    update(text)
    
def update(text):
    while len(text) > linelen:
github pygame / pygame / examples / midi.py View on Github external
print("using output_id :%s:" % port)

    midi_out = pygame.midi.Output(port, 0)
    try:
        midi_out.set_instrument(instrument)
        keyboard = Keyboard(start_note, n_notes)

        screen = pygame.display.set_mode(keyboard.rect.size)
        screen.fill(bg_color)
        pygame.display.flip()

        background = pygame.Surface(screen.get_size())
        background.fill(bg_color)
        dirty_rects = []
        keyboard.draw(screen, background, dirty_rects)
        pygame.display.update(dirty_rects)

        regions = pygame.Surface(screen.get_size())  # initial color (0,0,0)
        keyboard.map_regions(regions)

        pygame.event.set_blocked(MOUSEMOTION)
        mouse_note = 0
        on_notes = set()
        while 1:
            e = pygame.event.wait()
            if e.type == pygame.MOUSEBUTTONDOWN:
                mouse_note, velocity, __, __ = regions.get_at(e.pos)
                if mouse_note and mouse_note not in on_notes:
                    keyboard.key_down(mouse_note)
                    midi_out.note_on(mouse_note, velocity)
                    on_notes.add(mouse_note)
                else:
github jayniz / unicorn-hat-sim / unicorn_hat_sim.py View on Github external
self.AUTO = None
        self.PHAT = None
            
        # Set some defaults
        self.rotation_offset = rotation_offset
        self.rotation(0)
        self.pixels = [(0, 0, 0)] * width * height
        self.pixel_size = 15
        self.width = width
        self.height = height
        self.window_width = width * self.pixel_size
        self.window_height = height * self.pixel_size

        # Init pygame and off we go
        pygame.init()
        pygame.display.set_caption("Unicorn HAT simulator")
        self.screen = pygame.display.set_mode([self.window_width, self.window_height])
        self.clear()
github CodeSkool / SimpleGUI2Pygame / Videos / 2013Jul07Sun / ui.py View on Github external
def start(self):
        """Initialize pygame, set up the target and run the main game loop
        (handling events, drawing)."""
        pygame.init()
        self.clock = self.fpsClock = pygame.time.Clock()

        self.screen = pygame.display.set_mode((self.context.width,
                                               self.context.height))
        pygame.display.set_caption(self.context.title)

        # set up the target
        self.target.setup(self.screen)

        while True:
            if self.transitioning:
                # transition
                self.target = None
                return

            # fill the background color
            self.screen.fill(self.context.bg_color)
            # handle events
            self.handle_events()
github uthcode / learntosolveit / games / pygame / pygame_tut_16.py View on Github external
pix.draw(screen)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                pix.direction(UP)
            elif event.key == pygame.K_DOWN:
                pix.direction(DOWN)
            elif event.key == pygame.K_LEFT:
                pix.direction(LEFT)
            elif event.key == pygame.K_RIGHT:
                pix.direction(RIGHT)

    pygame.display.flip()
    clock.tick(0.24)
github buckyroberts / Source-Code-from-Tutorials / Pygame / 31_PythonGameDevelopment.py View on Github external
lead_x_change = 10
    lead_y_change = 0

    snakeList = []
    snakeLength = 1

    randAppleX = round(random.randrange(0, display_width-block_size))#/10.0)*10.0
    randAppleY = round(random.randrange(0, display_height-block_size))#/10.0)*10.0
    
    while not gameExit:

        while gameOver == True:
            gameDisplay.fill(white)
            message_to_screen("Game over", red, y_displace=-50)
            message_to_screen("Press C to play again or Q to quit",black, 50)
            pygame.display.update()

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gameOver = False
                    gameExit = True
                    
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        gameExit = True
                        gameOver = False
                    if event.key == pygame.K_c:
                        gameLoop()

        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
github huskyroboticsteam / 2016-17 / Prototyping / BaseStation / Examples / OldGUI / JoystickInterface.py View on Github external
RECTCOLOR = PURPLE
TEXTCOLOR = GOLD
POTCOLOR = RED
STOPCOLOR = RED

PI = math.pi

# Define initial characteristics of the screen
size = (700, 500)
screen = pygame.display.set_mode(size)
screen.fill(WHITE)
BUTTON = pygame.Rect(100, 100, 225, 200)
DISPLAY = pygame.Rect(100, 350, 400, 100)
STOP = pygame.Rect(475, 100, 200, 200)
POT = pygame.Rect(340, 100, 125, 200)
pygame.display.set_caption("The Interactive Joystick Interface")
font = pygame.font.SysFont('Arial', 25)

# Used to manage how fast the screen updates
clock = pygame.time.Clock()

# Processes the joystick values. Doubles if button for extra thrust is down, rounds values below 0.5 to 0
def joy2value(value, half_control=False):
    if half_control:
        value /= 2.0
    if abs(value - 0) < 0.05:
        value = 0
    return value

# Maps values to range from 0 to 255
def float256(value, low, high):
    value = 256 * (value - low) / (high - low)
github studywolf / blog / RL / combination allo and ego / cellular.py View on Github external
def setTitle(self, title):
        if not self.activated:
            return
        self.title = title
        title += ' %s' % makeTitle(self.world)
        if pygame.display.get_caption()[0] != title:
            pygame.display.set_caption(title)
github Podshot / MCEdit-Unified / mcplatform.py View on Github external
def askSaveFile(initialDir, title, defaultName, filetype, suffix):
    if sys.platform == "win32":  # !#
        try:
            if isinstance(suffix, (list, tuple)) and suffix:
                suffix = suffix[0]
            print repr(filetype)
            if not filetype.endswith("*.*\0*.*\0\0"):
                filetype = filetype[:-1] + "*.*\0*.*\0\0"
            print repr(filetype)
            (filename, customfilter, flags) = win32gui.GetSaveFileNameW(
                hwndOwner=display.get_wm_info()['window'],
                InitialDir=initialDir,
                Flags=win32con.OFN_EXPLORER | win32con.OFN_NOCHANGEDIR | win32con.OFN_OVERWRITEPROMPT,
                File=defaultName,
                DefExt=suffix,
                Title=title,
                Filter=filetype,
            )
        except Exception as e:
            print "Error getting file name: ", e
            return

        try:
            filename = filename[:filename.index('\0')]
            filename = filename.decode(sys.getfilesystemencoding())
        except:
            pass
github psychopy / psychopy / sandbox / openGL_FBO_withTextureShader.py View on Github external
#before flipping need to copy the renderBuffer to the frameBuffer
        GL.glColor4f(1,1,1,1)
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glBindTexture(GL.GL_TEXTURE_2D, frameTexture)
        GL.glBegin( GL.GL_QUADS )
        GL.glMultiTexCoord2f(GL.GL_TEXTURE0, 0.0, 0.0 ) 
        GL.glVertex2f( -1.0,-1.0 )
        GL.glMultiTexCoord2f(GL.GL_TEXTURE0, 0.0, 1.0 ) 
        GL.glVertex2f( -1.0, 1.0 )
        GL.glMultiTexCoord2f(GL.GL_TEXTURE0,1.0, 1.0 ) 
        GL.glVertex2f( 1.0,   1.0 )
        GL.glMultiTexCoord2f(GL.GL_TEXTURE0, 1.0, 0.0 ) 
        GL.glVertex2f( 1.0,   -1.0 )
        GL.glEnd()
    pygame.display.flip()
    
    if useFBO: 
        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        GL.glDisable(GL.GL_TEXTURE_2D)
        GL.glEnable(GL.GL_BLEND)
        
        FB.glBindFramebufferEXT(FB.GL_FRAMEBUFFER_EXT, frameBuffer)
def makeGrating():