Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.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 Shell重新启动而不是运行代码_Python_Class - Fatal编程技术网

Python Shell重新启动而不是运行代码

Python Shell重新启动而不是运行代码,python,class,Python,Class,试着用手指画一条直线 import turtle def draw_line(): window =turtle.Screen() window.bgcolor("blue") animal=turtle.Turtle () animal.forward(100) window.exitonclick() draw_line() 但是shell一直在重新启动,并且不运行代码。 救命啊 我尝试按如下方式运行您的代码: import turtle def draw_line():

试着用手指画一条直线

import turtle

def draw_line():
window =turtle.Screen()
window.bgcolor("blue")

animal=turtle.Turtle ()
animal.forward(100)

window.exitonclick()

draw_line()
但是shell一直在重新启动,并且不运行代码。
救命啊

我尝试按如下方式运行您的代码:

import turtle

def draw_line():
    window = turtle.Screen()
    window.bgcolor('blue')
    animal = turtle.Turtle()
    animal.forward(100)
    window.exitonclick()

draw_line()
我可以成功地运行它

我将上述代码保存在一个名为
turtle\u test.py
的文件中,并在命令行上运行它,如下所示:

python turtle_test.py
对我来说,它打开了一个带有预期输出的新窗口,并在单击时关闭

我用Python2.6和Python3.5都试过了。这两个版本的脚本都没有问题。但我必须提到的一点是,由该脚本创建的窗口没有自动获得焦点。我必须通过Alt-Tab'ing找到它,也许这也是你的问题


也很抱歉没有一个明确的答案,但我似乎需要“点”才能发表评论

缩进代码。无法理解def draw_sqaure“外壳”下的内容?什么贝壳?我道歉。我是说一个line@yusssk,仍然没有缩进,所以我们不知道函数定义何时完成(如果我们尝试复制并粘贴它,Python解释器也不会)?您是通过某种形式的GUI来运行它的吗?有时在将Tk与GUI混合使用时会出现问题,请尝试从命令行运行它。如果OP的缩进确实是他们在问题中提出的,那么这可以说是一个合理的答案。:)该死每次我尝试运行它时,它都返回>>>================================================================>>>。原因可能是什么?好吧,就像在你回答的评论中说的:看起来你在某种GUI中运行代码。你在用什么,你试着在命令行上运行这个吗?@jasper没有在任何GUI中运行代码,但是我不明白命令行是什么,这是我用python编程的第二天。我正在空闲状态下运行代码