turtle发射任务_少儿Python课堂练习

李兴球Python发射任务演示效果
上课了,请同学们仔细阅读代码,完成发射任务,具体请见演示动画。

import time
import turtle

def shoot_b1():
    """请完善这个函数的代码"""
turtle.delay(0)
turtle.setup(480,360)

b1 = turtle.Turtle('circle')
b1.left(90)
b1.speed(0)
b1.penup()
b1.ht()

cv = turtle.getcanvas()
按钮1 = turtle.TK.Button(text='发射',command=shoot_b1)
cv.create_window(0,150,window=按钮1)

square = turtle.Turtle('square')
square.shapesize(2)
square.ht()
square.penup()
square.goto(-240,150)
square.st()
dx = 2
while True:

    square.fd(dx)
    if square.xcor()>=240:
        square.ht()
        square.goto(-240,150)
        square.st()
   pass                      # 请在这里完善代码
        
    if b1.isvisible():
        b1.fd(10)
        if b1.ycor()>180:b1.ht()
    turtle.update()
    time.sleep(0.01)

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在python, tkinter, turtle分类目录。将固定链接加入收藏夹。

发表回复