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

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

    1. <tfoot id='xZSdL'></tfoot>

    2. 如何从 kivy 小部件画布中删除特定说明?

      How can I remove specific instructions from kivy widget canvas?(如何从 kivy 小部件画布中删除特定说明?)

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

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

        1. <tfoot id='JRBE0'></tfoot>
              <legend id='JRBE0'><style id='JRBE0'><dir id='JRBE0'><q id='JRBE0'></q></dir></style></legend>

              • <bdo id='JRBE0'></bdo><ul id='JRBE0'></ul>
                本文介绍了如何从 kivy 小部件画布中删除特定说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在编写一个基于 kivy 的图形应用程序,我可以在其中动态地将节点添加到绘图区域,然后将它们与有向线 (=edge) 连接起来.节点可以在绘图区域内拖动,边缘应始终与它们保持连接.

                I’m writing a kivy based graph app where I can dynamically add nodes to a draw area and then connect them with directed lines(=edge). Nodes can be dragged inside the draw area and edges should stay connected to them always.

                Edge 类派生自 Widget 类.它的图形表示由两部分组成,线本身(=线)和线的尖端(=三角形).当一个 Edge 小部件被绘制时,它的画布首先被平移和旋转,然后边缘的尖端被绘制到画布上.之后,画布被旋转回原来的位置,线条部分被绘制到canvas.after.

                Edge class is derived from Widget class. Its graphical presentation consists of two parts, the line itself(=Line) and the tip of the line(=Triangle). When an Edge widget is drawn, its canvas is at first translated and rotated after which the tip of the edge is drawn to the canvas. After that, the canvas is rotated back to its original position and the line part is drawn to canvas.after.

                当节点移动时,Edge 小部件的画布被清除并再次绘制图形表示.然而,这并没有按我的计划工作.

                When nodes are moved, the canvas of the Edge widget is cleared and the graphical presentation is drawn again. However, this doesn’t work as I planned.

                如果我在 Edge 类的 draw 方法的开头使用 self.canvas.clear() ,旧线不会被删除,我会在画布上得到多条线.

                If I use self.canvas.clear() at the beginning of the draw method of the Edge class, the old line is not removed and I get multiple lines on the canvas.

                如果我使用 self.canvas.after.clear(),我的绘图区域会完全混乱,因为 clear 方法还会从 canvas.after 中删除 PopMatrix 指令.

                If I use self.canvas.after.clear() I get a completely messed up view of my draw area, since the clear method also removes the PopMatrix instruction from the canvas.after.

                我怎样才能从 canvas.after 中删除线条的图形表示?有更好的方法吗?

                我的 Edge 类的 Kivy 文件:

                Kivy file of my Edge class:

                <Edge>:
                    id: ed
                    size_hint: None, None
                    canvas.before:
                        Color:
                            rgb: 0.9, 0.1, 0.1
                        PushMatrix
                        Translate:
                            x: ed.translate_x
                            y: ed.translate_y
                        Rotate:
                            angle: ed.rot_angle
                            origin: ed.rot_origin_x, ed.rot_origin_y
                    canvas.after:
                        PopMatrix
                

                更新我改变了我的方法,现在我在画布上绘制所有内容,而不是在画布和 canvas.after 上绘制.现在我得到了我想要的结果,但如果有人知道如何删除单独的画布指令,我会很高兴知道.

                UPDATE I changed my approach and now I draw everything on the canvas instead of drawing to canvas and canvas.after. Now I got the result that I wanted, but still if someone knows how to remove the individual canvas instructions it would be nice to know.

                推荐答案

                你可以:

                1. 通过执行 canvas.remove() 删除画布的子项,并传递所需的图形指令实例.您可以使用 canvas.children 进行迭代并获得一个.

                1. remove a children of a canvas by doing canvas.remove() and pass the instance of the graphics instructions you want. You can iterate and get the one with canvas.children.

                group 名称分配给画布属性,然后使用 canvas.remove_group().这是分类和删除大量图形指令而不保留对它们的引用的最佳方法.

                assign a group name to a canvas property, then use canvas.remove_group(). This is the best way to categorize and remove lot of graphics instructions without keeping a reference to them.

                这篇关于如何从 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中更改按钮或标签文本颜色)
                • <tfoot id='bMIbo'></tfoot>

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

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

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

                            <tbody id='bMIbo'></tbody>