<bdo id='L9Iju'></bdo><ul id='L9Iju'></ul>
  • <legend id='L9Iju'><style id='L9Iju'><dir id='L9Iju'><q id='L9Iju'></q></dir></style></legend>

      1. <tfoot id='L9Iju'></tfoot>
        <i id='L9Iju'><tr id='L9Iju'><dt id='L9Iju'><q id='L9Iju'><span id='L9Iju'><b id='L9Iju'><form id='L9Iju'><ins id='L9Iju'></ins><ul id='L9Iju'></ul><sub id='L9Iju'></sub></form><legend id='L9Iju'></legend><bdo id='L9Iju'><pre id='L9Iju'><center id='L9Iju'></center></pre></bdo></b><th id='L9Iju'></th></span></q></dt></tr></i><div id='L9Iju'><tfoot id='L9Iju'></tfoot><dl id='L9Iju'><fieldset id='L9Iju'></fieldset></dl></div>

        <small id='L9Iju'></small><noframes id='L9Iju'>

      2. Kivy标签中的文本下划线?

        时间:2023-10-10

      3. <legend id='pktSA'><style id='pktSA'><dir id='pktSA'><q id='pktSA'></q></dir></style></legend>

        <tfoot id='pktSA'></tfoot>

          <bdo id='pktSA'></bdo><ul id='pktSA'></ul>

          <small id='pktSA'></small><noframes id='pktSA'>

                <tbody id='pktSA'></tbody>
                <i id='pktSA'><tr id='pktSA'><dt id='pktSA'><q id='pktSA'><span id='pktSA'><b id='pktSA'><form id='pktSA'><ins id='pktSA'></ins><ul id='pktSA'></ul><sub id='pktSA'></sub></form><legend id='pktSA'></legend><bdo id='pktSA'><pre id='pktSA'><center id='pktSA'></center></pre></bdo></b><th id='pktSA'></th></span></q></dt></tr></i><div id='pktSA'><tfoot id='pktSA'></tfoot><dl id='pktSA'><fieldset id='pktSA'></fieldset></dl></div>
                  本文介绍了Kivy标签中的文本下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已阅读 kivy 中的 标签文档.粗体、斜体、字体、大小、颜色等属性效果很好.

                  I have read the documentation for Labels in kivy. Properties like bold, italic, font, size, color, etc. work pretty well.

                  但是,我怎样才能使标签文本加下划线?

                  However, how can I make the Label text underlined?

                  推荐答案

                  这是一个实现 我在 Google 网上论坛上找到:

                  from kivy.app import App
                  from kivy import kivy_options
                  from extended_markup import LabelXMU
                  
                  kivy_options['text']='pygame'
                  
                  class LabelWithMarkup(App):
                      def build(self):
                          root = LabelXMU(text=r"Some [b]bold[/b] [i]italic[/i] [u] underlined[/u] [s] strikethrough[/s] and plain text",   font_size=22)
                          return root
                  
                  if __name__ == '__main__':
                      LabelWithMarkup().run()
                  

                  extended.py:

                  from kivy.uix.label import Label
                  from kivy.core.text.markup import MarkupLabel
                  
                  try:
                      import pygame
                  except:
                      raise
                  #
                  #pygame_cache = {}
                  #pygame_cache_order = []
                  #
                  #pygame.font.init()
                  
                  
                  class CoreLabelXMU(MarkupLabel):
                      ''' A  core label with extended markup capabilities (underline and strikethrough markups)
                      Brendan Scott 6 March 2013
                      '''
                      def __init__(self, *largs, **kwargs):
                          self._style_stack = {}
                          self._refs = {}
                          super(MarkupLabel, self).__init__(*largs, **kwargs)    
                          self.options['underline'] = False
                          self.options['strike'] = False
                  
                  
                      def _pre_render(self):
                          # split markup, words, and lines
                          # result: list of word with position and width/height
                          # during the first pass, we don't care about h/valign
                          self._lines = lines = []
                          self._refs = {}
                          self._anchors = {}
                          spush = self._push_style
                          spop = self._pop_style
                          options = self.options
                          options['_ref'] = None
                  
                          for item in self.markup:
                              if item == '[b]':
                                  spush('bold')
                                  options['bold'] = True
                                  self.resolve_font_name()
                              elif item == '[/b]':
                                  spop('bold')
                                  self.resolve_font_name()
                              elif item == '[i]':
                                  spush('italic')
                                  options['italic'] = True
                                  self.resolve_font_name()
                              elif item == '[/i]':
                                  spop('italic')
                                  self.resolve_font_name()
                              elif item =='[s]':
                                  spush('strike')
                                  options['strike']=True  
                              elif item =='[/s]':
                                  spop('strike')
                              elif item =='[u]':
                                  spush('underline')
                                  options['underline']=True  
                              elif item =='[/u]':
                                  spop('underline')
                  
                              elif item[:6] == '[size=':
                                  item = item[6:-1]
                                  try:
                                      if item[-2:] in ('px', 'pt', 'in', 'cm', 'mm', 'dp', 'sp'):
                                          size = dpi2px(item[:-2], item[-2:])
                                      else:
                                          size = int(item)
                                  except ValueError:
                                      raise
                                      size = options['font_size']
                                  spush('font_size')
                                  options['font_size'] = size
                              elif item == '[/size]':
                                  spop('font_size')
                              elif item[:7] == '[color=':
                                  color = parse_color(item[7:-1])
                                  spush('color')
                                  options['color'] = color
                              elif item == '[/color]':
                                  spop('color')
                              elif item[:6] == '[font=':
                                  fontname = item[6:-1]
                                  spush('font_name')
                                  options['font_name'] = fontname
                                  self.resolve_font_name()
                              elif item == '[/font]':
                                  spop('font_name')
                                  self.resolve_font_name()
                              elif item[:5] == '[ref=':
                                  ref = item[5:-1]
                                  spush('_ref')
                                  options['_ref'] = ref
                              elif item == '[/ref]':
                                  spop('_ref')
                              elif item[:8] == '[anchor=':
                                  ref = item[8:-1]
                                  if len(lines):
                                      x, y = lines[-1][0:2]
                                  else:
                                      x = y = 0
                                  self._anchors[ref] = x, y
                              else:
                                  item = item.replace('&bl;', '[').replace(
                                          '&br;', ']').replace('&amp;', '&')
                                  self._pre_render_label(item, options, lines)
                  
                          # calculate the texture size
                          w, h = self.text_size
                          if h < 0:
                              h = None
                          if w < 0:
                              w = None
                          if w is None:
                              w = max([line[0] for line in lines])
                          if h is None:
                              h = sum([line[1] for line in lines])
                          return w, h
                  
                  
                  
                      def _render_text(self, text, x, y):
                          font = self._get_font()
                          if self.options['underline']:
                              font.set_underline(True)
                          else:
                              font.set_underline(False)
                  
                          color = [c * 255 for c in self.options['color']]
                          color[0], color[2] = color[2], color[0]
                          try:
                              text = font.render(text, True, color)
                              if self.options['strike']:
                                  ''' draw a horizontal line through the vertical middle of this surface in the foreground colour'''
                                  r = text.get_rect()
                                  pygame.draw.line(text, color, r.midleft, r.midright )
                  
                              self._pygame_surface.blit(text, (x, y), None, pygame.BLEND_RGBA_ADD)
                          except pygame.error:
                              pass
                  
                  
                  
                  class LabelXMU(Label):
                      ''' A label with extended markup capabilities (underline and strikethrough markups)
                      Brendan Scott 6 March 2013
                      '''
                  
                      def __init__(self, **kwargs):
                          kwargs['markup']=True
                          super(LabelXMU, self).__init__(**kwargs)
                          d = Label._font_properties
                          dkw = dict(zip(d, [getattr(self, x) for x in d]))
                          self._label = CoreLabelXMU(**dkw)
                  

                  这篇关于Kivy标签中的文本下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Kivy 使用 opencv.调整图像大小 下一篇:PyInstalled Kivy 应用程序无法在第二台机器上运行

                  相关文章

                  最新文章

                    • <bdo id='qsOqC'></bdo><ul id='qsOqC'></ul>
                  1. <tfoot id='qsOqC'></tfoot>

                    <i id='qsOqC'><tr id='qsOqC'><dt id='qsOqC'><q id='qsOqC'><span id='qsOqC'><b id='qsOqC'><form id='qsOqC'><ins id='qsOqC'></ins><ul id='qsOqC'></ul><sub id='qsOqC'></sub></form><legend id='qsOqC'></legend><bdo id='qsOqC'><pre id='qsOqC'><center id='qsOqC'></center></pre></bdo></b><th id='qsOqC'></th></span></q></dt></tr></i><div id='qsOqC'><tfoot id='qsOqC'></tfoot><dl id='qsOqC'><fieldset id='qsOqC'></fieldset></dl></div>

                    <small id='qsOqC'></small><noframes id='qsOqC'>

                      <legend id='qsOqC'><style id='qsOqC'><dir id='qsOqC'><q id='qsOqC'></q></dir></style></legend>