<tfoot id='puz93'></tfoot>

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

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

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

      <bdo id='puz93'></bdo><ul id='puz93'></ul>
    1. 将文本渲染到 kivy 画布

      时间:2023-10-08

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

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

            • <tfoot id='nlvdn'></tfoot>
                <tbody id='nlvdn'></tbody>
                <bdo id='nlvdn'></bdo><ul id='nlvdn'></ul>
                本文介绍了将文本渲染到 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 画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:加载表单后如何运行函数 Kivy 下一篇:带有 Kivy 的多台显示器

                相关文章

                最新文章

                <legend id='2ntLL'><style id='2ntLL'><dir id='2ntLL'><q id='2ntLL'></q></dir></style></legend>

                  • <bdo id='2ntLL'></bdo><ul id='2ntLL'></ul>

                  <small id='2ntLL'></small><noframes id='2ntLL'>

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