2017-07-12 3 views
-1
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() 

Répondre

0

Ce code n'exécute pas dans IDLE

Ce code ne s'exécute en dehors IDLE soit comme elle est boguée. Avez-vous vu pas le TypeError: unsupported operand type(s) for -: 'float' and 'Point' en raison de cette ligne:

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

Il vous apears un Oval à basculé un Circle mais n'a pas résolu les arguments. Aussi vous ne faites jamais mouth.draw(win) mais faites plutôt eye2.draw(win) deux fois probablement en raison d'une erreur copier-n-coller.

est ici une version retravaillée de votre programme qui fonctionne dans et à l'extérieur 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() 

Notez que la fenêtre graphique arrive derrière la fenêtre de la console IDLE (au moins sur mon système) et vous devra déplacer la console hors du chemin.