How to use the pyglet.text.Label function in pyglet

To help you get started, weā€™ve selected a few pyglet 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 microsoft / ptvsd / src / ptvsd / _vendored / pydevd / tests_mainloop / gui-pyglet.py View on Github external
#!/usr/bin/env python
"""Simple pyglet example to manually test event loop integration.

To run this:
1) Enable the PyDev GUI event loop integration for pyglet
2) do an execfile on this script
3) ensure you have a working GUI simultaneously with an
   interactive console
"""

if __name__ == '__main__':
    import pyglet
    
    
    window = pyglet.window.Window()
    label = pyglet.text.Label('Hello, world',
                              font_name='Times New Roman',
                              font_size=36,
                              x=window.width//2, y=window.height//2,
                              anchor_x='center', anchor_y='center')
    @window.event
    def on_close():
        window.close()
    
    @window.event
    def on_draw():
        window.clear()
        label.draw()
github johnmendel / python-tactics / scene.py View on Github external
def display_turn_notice(self, current_turn):
        if hasattr(self, 'turn_notice'):
            self.turn_notice.delete()
        self.turn_notice = Label(
                "Player %s's Turn" % (current_turn + 1),
                font_name='Times New Roman', font_size=36,
                x= 500 + self.camera.offset_x,
                y= 560 + self.camera.offset_y)
        self.turn_notice.color = 255 - (100 * current_turn), 255 - (100 * ((current_turn + 1) % 2)), 255, 255
github uthcode / learntosolveit / pyweek11 / version2 / ninelives.py View on Github external
#!/usr/bin/python

# A cat has nine lives.

import pyglet
from game import resources, load
from game import player

game_window = pyglet.window.Window(800, 600)
main_batch = pyglet.graphics.Batch()

player_ship = player.Player(x=400, y=300, batch = main_batch)

score_label = pyglet.text.Label(text="Score: 0", x = 10, y = 575,
        batch = main_batch)
level_label = pyglet.text.Label(text="A Cat Has Nine Lives.", x = 400, y = 575,
        anchor_x = 'center', batch = main_batch)

# The players should be an instance of the subclass
# pyglet.sprite.Sprite

cat_sprite = pyglet.sprite.Sprite(resources.cat_image, x=300, y=400,
        batch=main_batch)
rat_sprite = pyglet.sprite.Sprite(resources.rat_image, x=100,y=100,
        batch=main_batch)

lives = load.lives(3, cat_sprite.position, main_batch)

game_objects = [player_ship] + lives

game_window.push_handlers(player_ship)
github uthcode / learntosolveit / pyweek11 / version3 / ninelives.py View on Github external
# A cat has nine lives.

import pyglet
from game import resources, load
from game import player

game_window = pyglet.window.Window(800, 600)
game_window.set_caption("~ Grizzly Games ~")

# white color background.

pyglet.gl.glClearColor(1.0,1.0,1.0,1.0)

main_batch = pyglet.graphics.Batch()

score_label = pyglet.text.Label(text="Score: 0", x = 10, y = 575,
        batch = main_batch)
level_label = pyglet.text.Label(text="9 Lives.", x = 400, y = 575,
        anchor_x = 'center', batch = main_batch)

# Draw the Barb Fench
barb_horizontal1 = pyglet.sprite.Sprite(resources.barb_horizontal,x=0,y=0, batch = main_batch)
barb_horizontal2 = pyglet.sprite.Sprite(resources.barb_horizontal,x=0,y=540, batch = main_batch)
barb_vertical1 = pyglet.sprite.Sprite(resources.barb_vertical,x=0,y=0, batch = main_batch)
barb_vertical2 = pyglet.sprite.Sprite(resources.barb_vertical,x=740,y=0, batch = main_batch)

cat_sprite = player.Player(x=300, y=400, batch=main_batch)


lives = load.lives(9, cat_sprite.position, main_batch)

game_objects = [cat_sprite] + lives
github adamlwgriffiths / Pyglet / pyglet / window / __init__.py View on Github external
def __init__(self, window):
        from time import time
        from pyglet.text import Label
        self.label = Label('', x=10, y=10, 
                           font_size=24, bold=True,
                           color=(127, 127, 127, 127))

        self.window = window
        self._window_flip = window.flip
        window.flip = self._hook_flip

        self.time = 0.0
        self.last_time = time()
        self.count = 0
github los-cocos / cocos / samples / presentation / presentacion.py View on Github external
def __init__(self):

        super(HelloWorld, self).__init__()

        # see pyglet documentation for help on this lines
        self.text = pyglet.text.Label(
            'Hello, World!', font_name='', font_size=32, x=100, y=240, batch=self.batch)
github irskep / Space-Train / game / credits2 / __init__.py View on Github external
def spawn_text(text, size, x, y, dt=0):
    l = pyglet.text.Label(text, font_name=['Verdana', 'Helvetica'], font_size=norm_h*size, 
                          anchor_x='left', anchor_y='center', batch=myscene.batch,
                          color=(255, 255, 255, 255), x=norm_w*x, y=norm_h*y)
    if l.content_width > 960:
        l.delete()
        l = pyglet.text.Label(text, font_name=['Courier', 'Helvetica'], font_size=norm_h*size, 
                              anchor_x='left', anchor_y='center', batch=myscene.batch,
                              color=(255, 255, 255, 255), x=norm_w*x, y=norm_h*y,
                              multiline=True, width=960)
    def start_text():
        interp = FadeInterpolator(l, 'color', start=0, end=255, name="fade", duration=2.0)
        myscene.interp.add_interpolator(interp)
    
    def end_text(dt=0):
        interp = FadeInterpolator(l, 'color', start=255, end=0, name="fade", duration=2.0)
        myscene.interp.add_interpolator(interp)
github andrewrk / chem / run_game.py View on Github external
h = 18
        next_pos = self.lobby_pos + Vec2d(0, self.lobby_size.y - h)
        for user in self.users:
            nick = user['nick']
            if nick == self.nick:
                continue
            text = nick
            if user['playing'] is not None:
                text += " (playing vs %s)" % user['playing']
            elif self.nick in user['want_to_play']:
                text += " (click to accept challenge)"
            elif nick in self.challenged:
                text += " (challenge sent)"
            else:
                text += " (click to challenge)"
            label = pyglet.text.Label(text, font_size=13, x=next_pos.x, y=next_pos.y)
            self.nick_label[nick] = label
            self.nick_user[nick] = user
            next_pos.y -= h
            self.labels.append(label)
github traverseda / pycraft / pycraft / gs_running.py View on Github external
def __init__(self, config, height, width):
        super(GameStateRunning, self).__init__()
        self.world = World()
        self.player = Player(config["world"])

        # The crosshairs at the center of the screen.
        self.reticle = None
        # The label that is displayed in the top left of the canvas.
        self.game_info_label = pyglet.text.Label(
            '', font_name='Arial', font_size=18,
            x=10, y=height - 10, anchor_x='left', anchor_y='top',
            color=(0, 0, 0, 255))
        self.current_item_label = pyglet.text.Label(
            '', font_name='Arial', font_size=18,
            x=width - 10, y=10, anchor_x='right', anchor_y='bottom',
            color=(0, 0, 0, 255))
github TheMTank / GridUniverse / core / envs / rendering.py View on Github external
self.window.dispatch_events()

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) # todo needed?
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)

        # Draw text
        # todo fix font-size if maze is covering most of the screen
        fps_string = "FPS: {}".format(self.FPS)
        fps_label = pyglet.text.Label(text=fps_string, x=self.zoomed_width - len(fps_string) * self.font_size, y=self.zoomed_height - 80, font_size=self.font_size)
        fps_label.draw()

        if hasattr(self.env, 'step_num'):
            # todo get text size to properly align
            step_string = "Step: {}".format(self.env.step_num)

            step_num_label = pyglet.text.Label(text=step_string, x=self.zoomed_width - len(step_string) * self.font_size, y=self.zoomed_height - 160, font_size=self.font_size)
            step_num_label.draw()

        # Render agent
        self.agent_sprite.x, self.agent_sprite.y = self.get_x_y_pix_location(self.env.world[self.env.current_state][0], self.env.world[self.env.current_state][1])
        self.batch.draw()

        # Render all geoms e.g. policy arrows
        # self.draw_circle(500, 30)
        # self.line.end = (self.line.end[0], self.line.end[1] - 1)
        self.transform.enable()
        for geom in self.geoms:
            geom.render()
        for geom in self.onetime_geoms:
            geom.render()
        self.transform.disable()