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

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

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

      1. <i id='JM7Js'><tr id='JM7Js'><dt id='JM7Js'><q id='JM7Js'><span id='JM7Js'><b id='JM7Js'><form id='JM7Js'><ins id='JM7Js'></ins><ul id='JM7Js'></ul><sub id='JM7Js'></sub></form><legend id='JM7Js'></legend><bdo id='JM7Js'><pre id='JM7Js'><center id='JM7Js'></center></pre></bdo></b><th id='JM7Js'></th></span></q></dt></tr></i><div id='JM7Js'><tfoot id='JM7Js'></tfoot><dl id='JM7Js'><fieldset id='JM7Js'></fieldset></dl></div>
        <tfoot id='JM7Js'></tfoot>
      2. 在 Kivy 中创建动态绘制的线

        时间:2023-06-07

          <bdo id='3sVAv'></bdo><ul id='3sVAv'></ul>

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

            <small id='3sVAv'></small><noframes id='3sVAv'>

                  <tbody id='3sVAv'></tbody>
                  本文介绍了在 Kivy 中创建动态绘制的线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是我的帖子的延续:使用和移动小部件/按钮在基维

                  我想在 Kivy 中的两个节点(椭圆)之间创建一条线,以便在我移动节点时可以动态更新端点.这是我目前凌乱的框架:

                  I want to create a line between two nodes(ellipses) in Kivy, so that the end points can be dynamically updated as I move the nodes. Here is my current messy framework:

                      class GraphEdge(Widget):
                  
                          def __init__(self, **kwargs):
                              super(GraphEdge, self).__init__(**kwargs)
                              with self.canvas:
                                  Line(points=[100, 100, 200, 100, 100, 200], width=1)
                          pass
                  

                  我刚刚为积分添加了一些占位符值,因为我什至不知道如何开始使用应用程序中其他小部件的值.

                  I've just put in some placeholder value for the points, as I'm not sure how to even start using the values from the other widgets within the App.

                  我的最终目标是能够选择两个节点并单击一个按钮来添加行(或者更简洁的东西).我不是要别人为我制作这个,只是一些正确方向的指针会很棒:).

                  My end goal is to be able to select two nodes and click a button to add the line (or something even cleaner). I'm not asking someone to produce this for me, just some pointers in the right direction would be awesome :).

                  链接帖子中提供了更多信息,但如果需要,我很乐意在此处提供更多信息.

                  More info is available in the linked post, but I'm happy to put more here if requested.

                  谢谢.

                  附加信息:

                  我想根据某些事件更新线条的位置.例如,如果我将一个椭圆移到线上,我希望最近的边缘捕捉到椭圆并跟随它.

                  I want to update the position of the line based on some event. For example if I move an ellipse onto the line, I want the closest edge to snap to the ellipse and follow it.

                  def snap_to_node(self, node):
                      if self.collide_widget(node):
                          print "collision detected"
                          self.line.points=[node.pos]
                  

                  (这只是一个糟糕的尝试,我知道它根本不起作用)最终目标是能够将节点"与边"连接起来.

                  (This is just a poor attempt, I know it doesn't work at all) The end goal is to be able to connect 'nodes' with 'edges'.

                  所以我已经取得了一些进展.我创建了一个在时钟计划中调用的更新方法:

                  So I've made some progress. I created an update method which is called in the clock schedule:

                  def update(self, dt):
                      # detect node collision
                      self.edge.snap_to_node(self.node)
                  
                  
                  def snap_to_node(self, node):
                      if self.collide_widget(node):
                          print "collision detected"
                          self.line.points+=node.pos
                  

                  现在我想让它只更新一个点集(想法是我将其中一个线端捕捉到节点).

                  Now I want to make it so that I only update one of the point sets (the idea is that I snap one of the line ends to the node).

                  到目前为止,此代码仅检测在线点之一上的集合.并且附加点不会检测到碰撞.

                  So far this code only detects collections on one of the points of the line. And the additional points don't detect collisions.

                  推荐答案

                  Line(points=[100, 100, 200, 100, 100, 200], width=1)
                  

                  ^^ 你可以替换成

                  self.line = Line(points=[100, 100, 200, 100, 100, 200], width=1)
                  

                  然后稍后通过执行 self.line.width = 2self.line.points = [200, 100, 100, 200, 200, 100] 之类的操作来简单地修改线条.

                  Then later simply modify the line by doing things like self.line.width = 2 or self.line.points = [200, 100, 100, 200, 200, 100].

                  除此之外,我不确定你在问什么,你能更具体一点吗?

                  Other than that, I'm not sure what you're asking, could you be more specific?

                  这篇关于在 Kivy 中创建动态绘制的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:kivy 使用附加类来存储来自多个屏幕的数据 下一篇:Kivy 窗口隐藏/显示

                  相关文章

                  <tfoot id='szlSD'></tfoot>

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

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