是否有一个选择使用Python从Kivy现有线中删除点的选项



添加行的直接方法是使用:

line.ud["line"].points += [touch.x, touch.y]

我想问是否可以从行中删除点。我实际要做的是制作一条线,该线随着鼠标的移动而移动。

我想 points是列表的列表。

为了简化,我将用points变量将您的观点结构置于您的点结构。

  1. 您可以删除指定点(必须在列表中(

    points = [[1,2], [3,4], [5,6]]
    points.remove([3,4])
    print(points)  # [[1,2], [5,6]]
    
  2. 您可以在列表中弹出i-点数

    points = [[1,2], [3,4], [5,6]]
    removed_point = points.pop(1)  
    print(removed_point)  # [3,4] 
    print(points)  # [[1,2], [5,6]]
    
  3. 您可以切成列表以摆脱不需要的点

    points = [[1,2], [3,4], [5,6]]
    points = points[:1] + points[2:]
    print(points)  # [[1,2], [5,6]]
    

最新更新