此代码未在IDLE 3.6.1

时间:2017-07-12 09:48:39

标签: python-3.x zelle-graphics

from graphics import*
import time

def moveAll(shapeList,dx,dy):
    for shape in shapeList:
        shape.move(dx,dy)

def moveAllOnLine(shapeList,dx,dy,repititions,delay):
    for i in range(repititions):
        moveAll(shapeList,dx,dy)
        time.sleep(delay)

def main():
    winWidth=300
    winHeight=300
    win=GraphWin('bacnd forth.',winWidth,winHeight)
    win.setCoords(0,0,winWidth,winHeight)
    rect=Rectangle(Point(200,90),Point(220,100))
    rect.setFill("blue")
    rect.draw(win)
    head=Circle(Point(40,100),25)
    head.setFill("blue")
    head.draw(win)
    eye1=Circle(Point(30,105),5)
    eye1.setFill('blue')
    eye1.draw(win)
    eye2=Circle(Point(45,105),Point(55,105))
    eye2.setWidth(3)
    eye2.draw(win)
    mouth=Oval(Point(30,90),Point(50,85))
    mouth.setFill("red")
    eye2.draw(win)
    faceList=[head,eye1,eye2,mouth]
    cir2=Circle(Point(150,125),25)
    cir2.setFill("red")
    cir2.draw(win)
    moveAllOnLine(faceList,5,0,46,.05)
    moveAllOnLine(faceList,-5,0,46,.05)
    Text(Point(winWidth/2,20),'click here to quit').draw(win)
    win.getMouse()
    win.close()

main()

1 个答案:

答案 0 :(得分:0)

  

此代码未在IDLE

中执行

这个代码不是在IDLE之外执行,因为它是错误的。由于这一行,您没有看到TypeError: unsupported operand type(s) for -: 'float' and 'Point'

eye2=Circle(Point(45,105),Point(55,105))

它表示您将Oval切换为Circle但未修正参数。此外,您永远不会mouth.draw(win),而是因为复制粘贴错误而导致eye2.draw(win)两次。

这是在IDLE内外运行的程​​序的重写版本:

import time
from graphics import *

def moveAll(shapeList, dx, dy):
    for shape in shapeList:
        shape.move(dx, dy)

def moveAllOnLine(shapeList, dx, dy, repetitions, delay):
    for _ in range(repetitions):
        moveAll(shapeList, dx, dy)
        time.sleep(delay)

def main():
    winWidth, winHeight = 300, 300
    win = GraphWin('bacnd forth.', winWidth, winHeight)
    win.setCoords(0, 0, winWidth, winHeight)

    rect = Rectangle(Point(200, 90), Point(220, 100))
    rect.setFill("blue")
    rect.draw(win)

    head = Circle(Point(40, 100), 25)
    head.setFill("blue")
    head.draw(win)

    eye1 = Circle(Point(30, 105), 5)
    eye1.setFill('blue')
    eye1.draw(win)

    eye2 = Circle(Point(45, 105), 5)
    eye2.setWidth(3)
    eye2.draw(win)

    mouth = Oval(Point(30, 90), Point(50, 85))
    mouth.setFill("red")
    mouth.draw(win)

    faceList = [head, eye1, eye2, mouth]

    cir2 = Circle(Point(150, 125), 25)
    cir2.setFill("red")
    cir2.draw(win)

    moveAllOnLine(faceList, 5, 0, 46, 0.05)
    moveAllOnLine(faceList, -5, 0, 46, 0.05)

    Text(Point(winWidth / 2, 20), 'click here to quit').draw(win)

    win.getMouse()
    win.close()

main()

请注意,图形窗口出现 隐藏在 IDLE控制台窗口(至少在我的系统上),因此您需要将控制台移开。< / p>