当前位置: 首页>>代码示例>>Python>>正文


Python text.Label类代码示例

本文整理汇总了Python中pyglet.text.Label的典型用法代码示例。如果您正苦于以下问题:Python Label类的具体用法?Python Label怎么用?Python Label使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Label类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Button

class Button(Rectangle):
    def __init__(self, x, y, width, height, image=None, caption=None, batch=None, group=None):
        super(Button, self).__init__(x, y, width, height)
        self.batch = batch
        self.group = group
        self.sprite = None
        self.label = None
        if image:
            self.sprite = Sprite(image.get_region(0, 0, self.width, self.height), batch=self.batch, group=self.group)
        if caption:
            self.label = Label(caption, font_name='Arial', font_size=12,
                anchor_x='center', anchor_y='center', color=(255, 255, 255, 255), batch=self.batch,
                group=self.group)
        self.set_position(x, y)
	
    def set_position(self, x, y):
        super(Button, self).set_position(x, y)
        if self.sprite:
            self.sprite.x, self.sprite.y = x, y
        if self.label:
            self.label.x, self.label.y = self.get_center()

    def draw(self):
        if self.sprite:
            self.sprite.draw()
        if self.label:
            self.label.draw()
开发者ID:caront,项目名称:Minecraft,代码行数:27,代码来源:gui.py

示例2: draw_text

def draw_text(text, x, y, position, font_size):
    score = Label(
        text,
        font_name='League Gothic',
        font_size=font_size,
        x=x, y=y, anchor_x=position)
    score.draw()
开发者ID:SDRU,项目名称:had,代码行数:7,代码来源:draw.py

示例3: Button

class Button(object):
    """docstring for Button"""
    def __init__(self, text, x, y, width, height, batch, color=(50, 50, 50),
                 scale=unity, **kwargs):
        super(Button, self).__init__()
        self.pos = vec2(x, y) * scale
        self.width = width * scale.x
        self.height = height * scale.y
        self.bsize = 2 * scale.x
        self.color = color
        self.hcolor = hcolor
        self.text = Label(text, x=(self.pos.x + self.width / 2),
                          y=(self.pos.y + self.height / 2),
                          anchor_x='center', anchor_y='center',
                          batch=batch, **kwargs)
        self.bound = Rect(self.pos.x - self.bsize, self.pos.y - self.bsize,
                          self.width+2*self.bsize, self.height+2*self.bsize,
                          color=toplinecolor, batch=batch)
        self.rect = Rect(self.pos.x, self.pos.y, self.width, self.height,
                         color=self.color, batch=batch)

    def highlight(self):
        self.rect.update_color(self.hcolor)

    def restore(self):
        if not self.rect.color == self.color:
            self.rect.update_color(self.color)

    def over_button(self, x, y):
        return (0 < x - self.pos.x < self.width and
                0 < y - self.pos.y < self.height)

    def delete(self):
        self.text.delete()
        self.rect.delete()
开发者ID:mokapharr,项目名称:python_game,代码行数:35,代码来源:elements.py

示例4: QuitScreen

class QuitScreen(MenuClass):
    """docstring for QuitScreen"""
    def __init__(self, *args, **kwargs):
        super(QuitScreen, self).__init__(*args, **kwargs)
        self.buttons['quit'] = btn([300, 300], 'yes')
        self.buttons['dont_quit'] = btn([680, 300], 'no')
        self.text = 'do you really want to quit?'
        self.Label = Label(self.text, font_name=font,
                           font_size=36, bold=False,
                           x=640,
                           y=500,
                           anchor_x='center', anchor_y='center')
        self.Box = Box([340, 200], [600, 400], 2)

    def handle_clicks(self, key):
        if key == 'quit':
            self.send_message('kill_self')
        if key == 'dont_quit':
            self.send_message('menu_transition_-')

    def draw(self):
        self.Box.draw()
        for key_, panel in self.buttons.iteritems():
            panel.draw()
        self.Label.draw()
开发者ID:ashisdhara,项目名称:python_game,代码行数:25,代码来源:screens.py

示例5: UIHarvestChoose

class UIHarvestChoose(Panel, InputHandler):
    def __init__(self, trans, *a, **k):
        self.trans = trans
        cards = trans.cards
        self.inputlet = None

        w = 20 + (91 + 10) * 4 + 20
        h = 20 + 125 + 20 + 125 + 20 + 20

        self.lbl = Label(
            text=u"等待其他玩家操作", x=w//2, y=300, font_size=12,
            color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230),
            anchor_x='center', anchor_y='bottom'
        )

        Panel.__init__(self, width=1, height=1, zindex=5, *a, **k)
        parent = self.parent
        self.x, self.y = (parent.width - w)//2, (parent.height - h)//2 + 20
        self.width, self.height = w, h
        self.update()

        self.mapping = mapping = {}
        for i, c in enumerate(cards):
            y, x = divmod(i, 4)
            x, y = 20 + (91 + 10) * x, 20 + (125 + 20) * (1 - y)
            cs = CardSprite(c, parent=self, x=x, y=y)
            cs.associated_card = c
            mapping[id(c)] = cs

            @cs.event
            def on_mouse_dblclick(x, y, button, modifier, cs=cs):
                if cs.gray: return
                ilet = self.inputlet
                if not ilet: return
                ilet.set_card(cs.associated_card)
                ilet.done()

    def draw(self):
        Panel.draw(self)
        self.lbl.draw()

    def process_user_input_start(self, ilet):
        self.lbl.text = u'等待%s选择卡牌' % (ilet.actor.ui_meta.name)
        self.lbl.color = (255, 255, 160, 255)

    def process_user_input(self, ilet):
        assert ilet.actor is Game.getgame().me
        self.inputlet = ilet
        self.lbl.text = u'请你选择一张卡牌'
        self.lbl.color = (160, 251, 255, 255)

    def process_user_input_finish(self, ilet, rst):
        self.lbl.text = u'等待其他玩家操作'
        self.lbl.color = (255, 255, 160, 255)
        self.inputlet = None

    def on_harvest_choose(self, card):
        self.mapping[id(card)].gray = True
开发者ID:feisuzhu,项目名称:thbattle,代码行数:58,代码来源:inputs.py

示例6: created

 def created(self, data):
     self.savedPlayers = [0 for _ in xrange(4)]
     self.scoreCount = data.readShort(True)
     self.nameLength = data.readShort(True)
     self.flags = HIGHSCORE_FLAGS.copy()
     self.flags.setFlags(data.readShort(True))
     if self.flags['HideOnStart']:
         self.parent.visible = False
     self.hideScores = self.flags['HideScores']
     self.nameFirst = self.flags['NameFirst'] or self.hideScores
     self.font = LogFont(data, old = True)
     self.color = data.readColor()
     data.skipBytes(40)
     name_list = []
     score_list = []
     for _ in xrange(20):
         name_list.append(data.readString(41))
     for _ in xrange(20):
         score_list.append(data.readInt())
     self.originalScores = [(name_list[i], score_list[i])
         for i in xrange(self.scoreCount)]
     self.scores = self.originalScores[:]
     self.width = data.readShort(True)
     self.height = data.readShort(True)
     self.name = data.readString(260)
     self.enable_mouse()
     self.pendingScores = []
     self.set_file(self.name or 'Game.ini')
     if self.flags['CheckOnStart']:
         for index, item in enumerate(self.player.players.items):
             if item.score > self.scores[-1][1]:
                 self.pendingScores.insert(0, (item.score, index + 1))
     self.nameLabel = Label('Enter your name', color = (0, 0, 0, 255), 
         bold = True, anchor_x = 'center', anchor_y = 'center',
         y = 25)
     self.currentName = Label('', color = (0, 0, 0, 255), 
         anchor_x = 'center', anchor_y = 'center', width = BOX_WIDTH - 20)
     self.labels = labels = []
     height = self.height / self.scoreCount
     y = 0
     for name, score in self.scores:
         label1 = self.create_label(self.font, '', self.color, 
             self.width,
             self.height)
         label2 = self.create_label(self.font, '', self.color, 
             self.width, self.height)
         label2.set_style('align', 'right')
         for label in (label1, label2):
             label.y = y
         labels.append((label1, label2))
         y -= height
     self.update_labels()
     self.updateEnabled = True
     self.player.window.push_handlers(
         on_text_motion = self.on_text_motion,
         on_text = self.on_text,
         on_key_press = self.on_key_press
     )
开发者ID:Matt-Esch,项目名称:anaconda,代码行数:58,代码来源:kchisc.py

示例7: calculate

 def calculate(self):
     if self.name is None:
         return
     from pyglet.text import Label
     label = Label(self.text, self.name, self.size, self.bold, 
         self.italic, width = self.width)
     self.calculatedWidth = label.content_width
     self.calculatedHeight = label.content_height
     label.delete()
开发者ID:Matt-Esch,项目名称:anaconda,代码行数:9,代码来源:CalcRect.py

示例8: build

    def build(self):
        if not self.hidden and self.window.debug:
            batch = self.fg_batch
            self.stat_labels_l = []
            self.stat_labels_r = []
            y = self.y
            yo = 0
            x = self.x
            mainstat = self.owner.mainstat
            if mainstat == "str":
                c = lookup_color("darkred")
            elif mainstat == "agi":
                c = lookup_color("darkgreen")
            elif mainstat == "int":
                c = lookup_color("darkblue")
            else:
                c = lookup_color("yellow")
            label_l = Label(
                text="Main stat:", font_name=None, font_size=10,
                x=x, y=y-yo, anchor_x="left", anchor_y="top",
                color=lookup_color("black"), batch=batch
            )
            label_r = Label(
                text=mainstat, font_name=None, font_size=10,
                x=x+self.width, y=y-yo,
                anchor_x="right", anchor_y="top",
                color=c, batch=batch
            )
            self.stat_labels_l.append(label_l)
            self.stat_labels_l.append(label_r)
            yo += 16

            for stat, value in self.owner.base_stats.items():
                modvalue = self.owner.stats.get(stat)
                label_l = Label(
                    text=str(stat), font_name=None, font_size=8,
                    x=x, y=y-yo, anchor_x="left", anchor_y="top",
                    color=lookup_color("black", opacity=255),
                    batch=batch
                )
                label_r = Label(
                    text=str(modvalue), font_name=None, font_size=8,
                    x=x+self.width, y=y-yo,
                    anchor_x="right", anchor_y="top",
                    color=lookup_color("darkblue", opacity=255),
                    batch=batch
                )
                label_r.identifier = str(stat)
                self.stat_labels_l.append(label_l)
                self.stat_labels_r.append(label_r)
                yo += 12
            self.height = yo
            self.rectangle = create_rectangle(
                self.x, self.y,
                self.width, self.height,
                centered=False
            )
开发者ID:NiclasEriksen,项目名称:rpg_procgen,代码行数:57,代码来源:ui.py

示例9: __init__

class FloatingCombatText:

    def __init__(
        self, ui, text, x, y, duration=1.,
        scale=1., second_scale=0.5, growth=0.2, velocity=75,
        color="darkred", batch=None
    ):
        self.start_scale = scale
        self.second_scale = second_scale
        self.growth = growth
        self.x, self.y = x, y
        self.ui = ui
        wx, wy = self.ui.window.get_windowpos(x, y)
        self.color = lookup_color(color)
        self.label = Label(
            text=str(text), font_name=None, font_size=12 * scale,
            x=wx, y=wy, anchor_x="center", anchor_y="center",
            color=self.color, batch=batch,
        )
        self.velocity = velocity
        self.timer = duration
        self.duration = duration
        self.done = False

    def on_end(self):
        self.label.delete()
        self.done = True

    def update(self, dt):
        if self.timer <= 0:
            self.on_end()
        else:
            self.timer -= dt
            perc = self.timer / self.duration
            scale = (
                self.second_scale + (
                    (self.start_scale - self.second_scale) * perc
                )
            )
            self.y += self.velocity * dt
            self.label.font_size = 9 * scale
            self.label.x, self.label.y = self.ui.window.get_windowpos(
                self.x, self.y, precise=True
            )
            opacity = int(255 * perc)
            if opacity < 0:
                opacity = 0
            self.color = self.color[0], self.color[1], self.color[2], opacity
            self.label.color = self.color
开发者ID:NiclasEriksen,项目名称:rpg_procgen,代码行数:49,代码来源:ui.py

示例10: Label

class Label(Control):
    def __init__(self, text=u'Label',
                font_size=30, color=(0,0,0,255),
                x=0, y=0, bold=False, italic=False, *a, **k):
        self.rawlabel = RawLabel(
            text=text, font_size=font_size,
            color=color,x=0,y=0,
            anchor_x='left', anchor_y='bottom',
            bold=bold, italic=italic
        )
        w, h = self.rawlabel.content_width, self.rawlabel.content_height
        Control.__init__(self, x=x, y=y, width=w, height=h, *a, **k)

    def draw(self):
        self.rawlabel.draw()
开发者ID:17night,项目名称:thbattle,代码行数:15,代码来源:layouter.py

示例11: __init__

 def __init__(self, world, width, length, name, segments):
     # River
     self.world = world
     self.width = width
     self.name = name
     self.length = length
     self.segments = segments
     if (segments[0][0] > segments[-1][0]):
         self.segments.reverse()
     # Neighborhoods
     self.chood = None
     self.rhood = None
     # Label
     self.ltuple = None
     self.oldltuple = None
     self.candidates = None
     self.label = Label(name, font_name=FONTNAME, font_size=RIVER_LABEL_HEIGHT, 
                        italic=True, color=(76,76,128,255))
     # Glyph data
     self.glyphs = fontload(FONTNAME, RIVER_LABEL_HEIGHT, italic=True).get_glyphs(self.name)
     self.label_hiline = map((lambda x: x.vertices[3]), self.glyphs)
     self.label_loline = map((lambda x: x.vertices[1]), self.glyphs)
     self.label_swathwidth = int(1.2 * self.label.content_width)
     self.label_ascent = max(self.label_hiline)
     self.label_idealdist = self.label_ascent/4.0 + self.width/2.0
     # Visualization
     self.lines = []
     for s in self.segments: self.lines.extend([s[0], s[1]])             
     # Debug
     self.debugpointsA = []
     self.debugpointsB = []
     self.debugpointsC = []
     # Cache
     self.rlcf = None
     self.rlrf = None
开发者ID:ajhalme,项目名称:maplabel,代码行数:35,代码来源:Maplabel.py

示例12: add_to_batch

 def add_to_batch(self, batch, groups):
     self.titleLabel = Label(
         'Sinister Ducks',
         font_size=36,
         x=self.game.width / 2, y=self.game.height / 2 + 30,
         anchor_x='center', anchor_y='center',
         batch=batch,
         group=groups[self.render_layer] )
     self.pressAnyKeyLabel = Label(
         'Press any key',
         font_size=18,
         x=self.game.width / 2, y=self.game.height / 2 - 20,
         anchor_x='center', anchor_y='center',
         batch=batch,
         group=groups[self.render_layer] )
     self.blink(None)
开发者ID:mjs,项目名称:brokenspell,代码行数:16,代码来源:hudtitle.py

示例13: __init__

    def __init__(self, parent, x, y, width, height,
                 sb_width, sb_height,
                 style=0, 
                 background_image=None,
                 scrollbar_image=None, 
                 caption=None, font_size=12, font_name=G.DEFAULT_FONT,
                 batch=None, group=None, label_group=None,
                 pos=0, on_pos_change=None,
                 *args, **kwargs):
        super(ScrollbarWidget, self).__init__(parent, *args, **kwargs)
        parent.push_handlers(self)
        self.batch = pyglet.graphics.Batch() if not batch else batch
        self.group = group
        self.label_group = label_group
        self.x, self.y, self.width, self.height = x, y, width, height
        self.sb_width, self.sb_height = sb_width, sb_height

        self.style = style
        if self.style == 0:
            self.sb_width = self.width
        else:
            self.sb_height = self.height

        self.background = image_sprite(background_image, self.batch, self.group)
        self.background.scale = max(float(self.width) / float(background_image.width), float(self.height) / float(background_image.height))
        self.scrollbar = image_sprite(scrollbar_image, self.batch, self.group)
        self.scrollbar.scale = max(float(self.sb_width) / float(scrollbar_image.width), float(self.sb_height) / float(scrollbar_image.height))

        self.pos = pos
        self.on_pos_change = on_pos_change
        self.caption = caption
        self.label = Label(str(caption) + ":" + str(pos) + "%", font_name, 12, anchor_x='center', anchor_y='center',
            color=(255, 255, 255, 255), batch=self.batch, group=self.label_group) if caption else None
        
        self.move_to(x, y)
开发者ID:boskee,项目名称:Minecraft,代码行数:35,代码来源:gui.py

示例14: __init__

    def __init__(self, trans, *a, **k):
        self.trans = trans
        cards = trans.cards
        self.inputlet = None

        w = 20 + (91 + 10) * 4 + 20
        h = 20 + 125 + 20 + 125 + 20 + 20

        self.lbl = Label(
            text=u"等待其他玩家操作", x=w//2, y=300, font_size=12,
            color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230),
            anchor_x='center', anchor_y='bottom'
        )

        Panel.__init__(self, width=1, height=1, zindex=5, *a, **k)
        parent = self.parent
        self.x, self.y = (parent.width - w)//2, (parent.height - h)//2 + 20
        self.width, self.height = w, h
        self.update()

        self.mapping = mapping = {}
        for i, c in enumerate(cards):
            y, x = divmod(i, 4)
            x, y = 20 + (91 + 10) * x, 20 + (125 + 20) * (1 - y)
            cs = CardSprite(c, parent=self, x=x, y=y)
            cs.associated_card = c
            mapping[id(c)] = cs

            @cs.event
            def on_mouse_dblclick(x, y, button, modifier, cs=cs):
                if cs.gray: return
                ilet = self.inputlet
                if not ilet: return
                ilet.set_card(cs.associated_card)
                ilet.done()
开发者ID:feisuzhu,项目名称:thbattle,代码行数:35,代码来源:inputs.py

示例15: Button

class Button(pyglet.event.EventDispatcher, Rectangle):
    def __init__(self, parent, x, y, width, height, image=None, image_highlighted=None, caption=None, batch=None, group=None, label_group=None, font_name=G.DEFAULT_FONT):
        super(Button, self).__init__(x, y, width, height)
        parent.push_handlers(self)
        self.batch, self.group, self.label_group = batch, group, label_group
        self.sprite = image_sprite(image, self.batch, self.group)
        self.sprite_highlighted = hidden_image_sprite(image_highlighted, self.batch, self.group)
        self.highlighted = False
        self.label = Label(str(caption), font_name, 12, anchor_x='center', anchor_y='center',
            color=(255, 255, 255, 255), batch=self.batch, group=self.label_group) if caption else None
        self.position = x, y

    @property
    def position(self):
        return self.x, self.y

    @position.setter
    def position(self, position):
        self.x, self.y = position
        if hasattr(self, 'sprite') and self.sprite:
            self.sprite.x, self.sprite.y = position
        if hasattr(self, 'sprite_highlighted') and self.sprite_highlighted:
            self.sprite_highlighted.x, self.sprite_highlighted.y = position
        if hasattr(self, 'label') and self.label:
            self.label.x, self.label.y = self.center

    def draw(self):
        self.draw_sprite()
        self.draw_label()

    def draw_sprite(self):
        if self.sprite and not (self.sprite_highlighted and self.highlighted):
            self.sprite_highlighted.visible, self.sprite.visible = False, True
            self.sprite.draw()
        elif self.sprite_highlighted and self.highlighted:
            self.sprite_highlighted.visible, self.sprite.visible = True, False
            self.sprite_highlighted.draw()

    def draw_label(self):
        if self.label:
            self.label.draw()

    def on_mouse_click(self, x, y, button, modifiers):
        if self.hit_test(x, y):
            self.dispatch_event('on_click')
开发者ID:tfaris,项目名称:Minecraft,代码行数:45,代码来源:gui.py


注:本文中的pyglet.text.Label类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。