在Python课堂上用的一个小程序,抽到的同学需要把学习的内容讲解出来。以下是完整版代码。
import random
import turtle
def begin():
global flag ,counter # 声明flag是全局变量,(因为要在函数中改变它值)
flag = True
b1.config(state='disabled') # 让b1按钮失效
counter = 0
select()
def end():
global flag
flag = False
b1.config(state='normal')
def select():
global counter
if flag==True:
counter += 1
turtle.clear() # 清除以前写的字
name = random.choice(names) # 从names列表中随机选择一个名字,赋值给name
screen.title(name)
turtle.sety(0)
turtle.color('cyan') # 海龟颜色为青
turtle.write(name,align='center',font=('黑体',42,'normal'))
turtle.sety(-60)
turtle.color('red') # 海龟颜色为lime
turtle.write(counter,align='center',font=('黑体',32,'normal'))
screen.ontimer(select,100) # 通过ontimer命令,让select函数在100毫秒后再次运行
names = ['罗*宁','郭*尘','汤*','裴*玮','余*恒','赵*阳','李*顺',
'王*禹','王*睿','刘*宇','冯*程','朱*涵','肖*欣']需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

