Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 蟒蛇龟点会无缘无故地闪烁_Python_Python Turtle - Fatal编程技术网

Python 蟒蛇龟点会无缘无故地闪烁

Python 蟒蛇龟点会无缘无故地闪烁,python,python-turtle,Python,Python Turtle,在我的程序中,为了模拟运动,添加点的x位置,清除旧点,并绘制一个新点 def drawing_zombies(): clear() for zombie in zombies: goto(zombie.x, zombie.y) dot(20, 'red') update() def movement(): for zombie in zombies: zombie.x -= 0.5 drawing_zombies() 我看过一个非常相似的程序运行,

在我的程序中,为了模拟运动,添加点的x位置,清除旧点,并绘制一个新点

def drawing_zombies():
  clear()
  for zombie in zombies:
    goto(zombie.x, zombie.y)
    dot(20, 'red')
  update()

def movement():
  for zombie in zombies:
    zombie.x -= 0.5
  drawing_zombies()
我看过一个非常相似的程序运行,它的点没有闪烁,看起来它真的在移动。然而,当我的程序运行时,它闪烁消失,并以极快的速度重新出现

下面是代码的其余部分,除了定义vector类的一系列内容之外,vector类与工作程序中的内容相同,因此其中没有任何内容是问题所在

class vector(collections.abc.Sequence):
    precision = 6
    __slots__ = ('_x', '_y', '_hash')

    def __init__(self, x, y):
        self._hash = None
        self._x = round(x, self.precision)
        self._y = round(y, self.precision)
    #The rest of the vector class would have been here

zombies = []
placement_options = [0, 1, 2, -1]

def new_zombie():
    placement_level = random.choice(placement_options)
    z = vector(200, placement_level*100)
    print(placement_level)
    zombies.append(z)

def drawing_zombies():
  clear()
  for zombie in zombies:
    goto(zombie.x, zombie.y)
    dot(20, 'red')
  update()

def movement():
  for zombie in zombies:
    zombie.x -= 0.5
  drawing_zombies()

  for z in zombies:
    if z.x < -200:
      done()
  ontimer(movement(), 50)

def gameplay():
  setup(420, 420, 370, 0)
  hideturtle()
  up()
  new_zombie()
  movement()
  done()


gameplay()
您可以使用tracerFalse功能禁用屏幕更新。因此,基本上,所有的绘图都是在内存中完成的,当您调用tracerTrue时,会立即复制到屏幕上


尝试在函数开始处添加turtle.tracerFalse,在函数结束处添加turtle.tracerTrue。确定。“今天不能做,但我明天会测试。”约翰尼莫普说。你应该回答这个问题。
def drawing_zombies():
  tracer(False)
  clear()
  for zombie in zombies:
    goto(zombie.x, zombie.y)
    dot(20, 'red')
  update()
  tracer(True)