简体   繁体   English

为什么我在运行此程序时会收到 Terminator 错误?

[英]Why do I get a Terminator error when I run this program?

Here is my code:这是我的代码:

import os
from turtle import *
sc = Screen()
sc.setup(600,600)
image = os.path.expanduser("~\OneDrive\Desktop\AlienGameImage.gif")
sc.register_shape(image)
t = Turtle()
t.shape(image)
sc.exitonclick()

Whenever I run this program, the first time it comes up with this error (Error below).每当我运行这个程序时,它第一次出现这个错误(下面的错误)。 However, the second time I run it, it runs fine.但是,我第二次运行它时,它运行良好。 Error:错误:

Traceback (most recent call last):

  File "C:\Users\hulks\.spyder-py3\untitled0.py", line 14, in <module>
    t = Turtle()

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 3813, in __init__
    RawTurtle.__init__(self, Turtle._screen,

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 2557, in __init__
    self._update()

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 2660, in _update
    self._update_data()

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 2646, in _update_data
    self.screen._incrementudc()

  File "C:\Users\hulks\anaconda3\lib\turtle.py", line 1292, in _incrementudc
    raise Terminator

Terminator

The error comes from here in turtle.py:错误来自turtle.py中的此处:

def _incrementudc(self):
    """Increment update counter."""
    if not TurtleScreen._RUNNING:
        TurtleScreen._RUNNING = True
        raise Terminator
    if self._tracing > 0:
        self._updatecounter += 1
        self._updatecounter %= self._tracing

I don't want to have to run this code twice every time so if anyone has a solution, I thank you in advance.我不想每次都运行这段代码两次,所以如果有人有解决方案,我提前谢谢你。

Don't call both:不要同时调用:

sc.exitonclick()
mainloop()

It's one or the other as exitonclick() simply sets up the exit key event and calls mainloop()它是其中之一,因为exitonclick()只是设置退出键事件并调用mainloop()

TurtleScreen._RUNNING is False when the program is executed for the first time, so it will enter the judgment formula and throw a Terminator exception TurtleScreen._RUNNING程序第一次执行时为False ,所以会进入判断公式,抛出Terminator异常

TurtleScreen._RUNNING is True when the program is executed for the second time, skipping the judgment formula, so it executes smoothly. TurtleScreen._RUNNING程序第二次执行时为True ,跳过判断公式,因此执行流畅。

Delete raise Terminator , you can solve the problem.删除raise Terminator ,即可解决问题。

I can see from your filepath that you are running it from spyder.我可以从您的文件路径中看到您正在从 spyder 运行它。 The turtle module uses a class variable TurtleScreen._RUNNING which remains false after a destroy between executions when running in spyder instead of running it as a self contained script. Turtle 模块使用 class 变量 TurtleScreen._RUNNING 在 spyder 中运行而不是将其作为自包含脚本运行时,在执行之间的破坏后保持为假。 I have requested for the module to be updated.我已要求更新模块。

Meanwhile, work around/working examples同时,解决/工作示例

1) 1)

import os
import importlib
import turtle
importlib.reload(turtle)
sc = Screen()
sc.setup(600,600)
image = os.path.expanduser(r"~\OneDrive\Desktop\AlienGameImage.gif")
sc.register_shape(image)
t = turtle.Turtle()
t.shape(image)
sc.exitonclick()

import os
import turtle
sc = Screen()
sc.setup(600,600)
image = os.path.expanduser(r"~\OneDrive\Desktop\AlienGameImage.gif")
sc.register_shape(image)
turtle.TurtleScreen._RUNNING=True
t = turtle.Turtle()
t.shape(image)
sc.exitonclick()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我不断收到 Python Turtle 的终结者错误? - Why do I keep getting a Terminator error for Python Turtle? 为什么我的程序出现错误 - Why do I get an error in my program 为什么我在 pycharm 和 IDLE 中运行相同的程序会得到不同的结果? - Why do I get different results when I run the same program in pycharm and IDLE? 当我从Django网站使用PyVirtualDisplay运行Selenium时,为什么会出现gnome权限错误? - Why do I get a gnome permissions error when I run Selenium using PyVirtualDisplay from a Django website? 当我尝试使用 docker 镜像运行 donkeycar 服务器时,为什么会出现错误? - Why do I get an error when I try to run donkeycar server using the docker image? 为什么我在尝试运行 discord 机器人时会出错? - Why do I get error when I am trying to run my discord bot? 当我尝试运行我的机器人时,为什么会出现这个奇怪的错误? (discord.py) - Why do i get this weird error when i try to run my bot? (discord.py) 为什么在运行 runmodwsgi 时会出现“split”属性丢失的错误? - Why do I get the error that the 'split' attribute is missing when I run runmodwsgi? 当我从virtualenv运行nosetests时,为什么会出现“无效的命令nosetests”错误? - Why do I get the error “Invalid command nosetests” when I run nosetests from my virtualenv? 为什么在运行manage.py validate时出现错误? - Why do I get error when i run manage.py validate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM