• <small id='ty1CF'></small><noframes id='ty1CF'>

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

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

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

        <tfoot id='ty1CF'></tfoot>
      1. 将文本渲染到 kivy 画布

        Rendering text to a kivy canvas(将文本渲染到 kivy 画布)

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

          • <bdo id='LlFFc'></bdo><ul id='LlFFc'></ul>
          • <tfoot id='LlFFc'></tfoot>

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

                    <tbody id='LlFFc'></tbody>
                  <legend id='LlFFc'><style id='LlFFc'><dir id='LlFFc'><q id='LlFFc'></q></dir></style></legend>

                1. 本文介绍了将文本渲染到 kivy 画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 kivy 的画布"中绘制自己的图形.现在我有一个每秒改变一次颜色的红色或绿色矩形,但我想添加一个不断变化的文本标签.

                  I am trying to draw my own graphic within a kivy 'canvas'. For now I have a red or green rectangle which changes colour once per second, but I want to add a changing text label.

                  经过一番搜索,似乎没有可以添加到画布的文本"指令.我发现了一些关于使用 Label() 小部件以及画布说明的参考,但这似乎并不理想,而且我似乎无法让它多次渲染.

                  After a little searching it appears that there isn't a "Text" Instruction which can be added to the canvas. I have found a few references to using a Label() widget as well as the canvas Instructions, but this does not seem ideal, and also I can't seem to get it to render more than once.

                  这是我目前的对象:

                  class HVObject(BoxLayout):
                      def __init__(self, **kwargs):
                          BoxLayout.__init__(self, **kwargs)
                          self.colour = 1
                          self.label = Label()
                          self.render()
                          self.add_widget(self.label)
                  
                          self.bind(size=self._update_rect, pos=self._update_rect)
                          Clock.schedule_interval(self.callevery, 1)
                  
                      def render(self):
                          self.canvas.clear()
                          self.rect = Rectangle(size=self.size, pos=self.pos)
                          self.canvas.add(Color(1-self.colour, self.colour, 0, 1))
                          self.canvas.add(self.rect)
                          self.label.text = "COL %d" % self.colour
                          self.canvas.ask_update()
                  
                      def callevery(self, x):
                          self.colour = 1-self.colour
                          self.render()
                  
                      def _update_rect(self, instance, value):
                          self.rect.pos = instance.pos
                          self.rect.size = instance.size
                          self.label.pos = instance.pos
                  

                  有没有简单的方法可以达到我需要的效果?

                  Is there an easy way to achieve the effect I need?

                  谢谢

                  推荐答案

                  回答我自己的问题:

                  在 [kivy] 花园周围看了一圈后,我找到了 Tickline(和 Tick).以及 CoreLabel() 和 Rectangle(texture=...) 的使用

                  After a little look around the [kivy] garden, I found Tickline (and Tick). and the use of CoreLabel() and Rectangle(texture=...)

                  这是我更新的 render() 方法,它添加了我需要的文本对象.

                  Here's my updated render() method which adds the text object I need.

                      def render(self):
                          self.canvas.clear()
                          self.canvas.add(Color(1-self.colour, self.colour, 0, 1))
                          self.rect = Rectangle(size=self.size, pos=self.pos)
                          self.canvas.add(self.rect)
                          label = CoreLabel(text="COL %d" % self.colour, font_size=20)
                          label.refresh()
                          text = label.texture
                          self.canvas.add(Color(self.colour, 1-self.colour,0, 1))
                          pos = list(self.pos[i] + (self.size[i] - text.size[i]) / 2 for i in range(2))
                          self.canvas.add(Rectangle(size=text.size, pos=pos, texture=text))
                          self.canvas.ask_update()
                  

                  这对我有用,虽然有点笨重!

                  Which works for me, albeit a little clunky!

                  这篇关于将文本渲染到 kivy 画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                  Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                  How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                  Centering an object in Kivy(在 Kivy 中将对象居中)
                  How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                  Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)
                2. <legend id='ZIgaB'><style id='ZIgaB'><dir id='ZIgaB'><q id='ZIgaB'></q></dir></style></legend>
                  1. <tfoot id='ZIgaB'></tfoot>
                  2. <small id='ZIgaB'></small><noframes id='ZIgaB'>

                        <tbody id='ZIgaB'></tbody>
                        <bdo id='ZIgaB'></bdo><ul id='ZIgaB'></ul>

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