以下是完整版代码:
""" 淘气的窗口.py 有个海龟画图窗口很淘气,你单击一下它,它就会跑,还会给你颜色看! """ import random from turtle import Screen def move_random(x,y): """单击窗口会随机移到windows屏幕任一位置""" r = random.randint(1,255) g = random.randint(1,255) b = random.randint(1,255) screen.bgcolor(r,g,b) x = random.randint(0,1023) y = random.randint(0,767) screen.setup(startx=x,starty=y,width=200,height=200) screen = Screen() screen.colormode(255) screen.setup(200,200) screen.screensize(100,100) # 设定画布尺寸 screen.title('请单击屏幕任一位置') # 设定标题 screen.onclick(move_random) # 绑定单击事件到move_random函数 screen.mainloop() # 进入主循环
发表评论