当我要求用户输入海龟时,海龟页面冻结。
我试过使用turtle.mainloop(),但这只会完全停止程序。
有没有一种方法可以防止海龟页面冻结和程序停止?
这是代码:
import turtle
import time
import random
def quickshape(sides,size,thickness):
int(thickness)
turtle.width(thickness)
int(sides)
int(size)
angle = 360 / sides
int(angle)
for i in range(sides):
turtle.forward(size)
turtle.right(angle)
def correct_position():
global x
global y
turtle.penup()
x = random.randint(-400,400)
y = random.randint(-250,250)
turtle.setpos(x, y)
def move_alot():
global x
global y
turtle.penup()
x += random.randint(-100,100)
y += random.randint(-100,100)
goes = 1
print("My Doodle .co can draw you lots of shapes, depending on what you ask us!")
print("To make a new set of patterns, close the pattern page... but only when it is drawing.")
print()
print("Before we start, do you want day or night mode?")
while True:
mode = input("Mode: ")
if mode == 'day' or mode[0] == 'd':
print("Day mode it is.")
mode = 'day'
break
elif mode == 'night' or mode[0] == 'n':
print("Night mode it is.")
mode = 'night'
break
else:
print("Hmm... which mode?")
titlename = input("Title: ")
print("Configuring - takes a couple of seconds...")
while True:
turtle.ht()
turtle.tracer(0)
turtle.screensize()
turtle.setup(width = 1.0, height = 1.0)
turtle.title(titlename + " [waiting for input - do not close]")
print("[ pattern",goes,"]")
while True:
try:
sides = int(input("Sides: "))
except ValueError:
print("[Input Error]")
else:
if sides > 35:
print("Warning: >35 sides")
break
try:
turtle.penup()
x = random.randint(-200,200)
y = random.randint(-100,100)
turtle.setpos(x, y)
浮云间
相关分类