第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在不使用 turtle.mainloop() 的情況下停止海龜凍結(jié)?

如何在不使用 turtle.mainloop() 的情況下停止海龜凍結(jié)?

紅糖糍粑 2023-02-15 17:36:06
當(dāng)我要求用戶(hù)輸入海龜時(shí),海龜頁(yè)面凍結(jié)。我試過(guò)使用turtle.mainloop(),但這只會(huì)完全停止程序。有沒(méi)有一種方法可以防止海龜頁(yè)面凍結(jié)和程序停止?這是代碼:import turtle  import time import randomdef 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 = 1print("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)
查看完整描述

1 回答

?
浮云間

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超4個(gè)贊

這是代碼 - 但它對(duì)問(wèn)題來(lái)說(shuō)不太重要。


代碼對(duì)問(wèn)題總是很重要!


有足夠的代碼,而且問(wèn)題相當(dāng)模糊,我將嘗試將您的代碼翻譯成 Python 的方法;-),看看您的問(wèn)題是否仍然存在:


from turtle import Screen, Turtle

from random import random, randint


def quickshape(sides, size, thickness):

    turtle.width(thickness)

    angle = 360 / sides


    for _ in range(sides):

        turtle.forward(size)

        turtle.right(angle)


def correct_position():

    global x, y


    x = randint(-400, 400)

    y = randint(-250, 250)


def move_alot():

    global x, y


    x += randint(-100, 100)

    y += randint(-100, 100)


print("My Doodle .co can draw you lots of shapes, depending on what you ask us!")

print()

print("Before we start, do you want day or night mode?")


goes = 1


while True:

    mode = input("Mode: ")


    if mode[0].lower() == 'd':

        print("Day mode it is.")

        mode = 'day'

        break


    if mode[0].lower() == 'n':

        print("Night mode it is.")

        mode = 'night'

        break


    print("Hmm... which mode?")


titlename = input("Title: ")

print("Configuring - takes a couple of seconds...")


screen = Screen()

screen.tracer(False)

screen.setup(width=1.0, height=1.0)


if mode == 'day':

    screen.bgcolor("white")

else:

    screen.bgcolor("black")


turtle = Turtle()

turtle.hideturtle()


while True:

    screen.title(titlename + " [Waiting for input - do not close]")

    pattern = "[Pattern {}]".format(goes)


    sides = screen.numinput(pattern, "Number of sides:", default=6, minval=3, maxval=35)


    if sides is None:

        break


    sides = int(sides)  # numinput() returns float


    numshapes = screen.numinput(pattern, "Number of shapes:", default=3, minval=1, maxval=50)


    if numshapes is None:

        break


    numshapes = int(numshapes)


    size = screen.numinput(pattern, "Length of each side:", default=25, minval=5, maxval=500)


    if size is None:

        break


    thickness = screen.numinput(pattern, "Thickness of pen:", default=1, minval=1, maxval=10)


    if thickness is None:

        break


    x = randint(-200, 200)

    y = randint(-100, 100)


    for part in range(1, numshapes + 1):

        turtle.penup()


        percentage = round(part/numshapes * 100, 2)

        screen.title(titlename + " [Drawing pattern. " + str(percentage) + "% complete.]")


        turtle.color(random(), random(), random())


        if randint(1, 45) == 1:

            move_alot()

        else:

            x += randint(-10, 5)

            y += randint(-5, 10)


        if not (-650 < x < 650 and -500 < y < 500):

            correct_position()


        turtle.setposition(x, y)

        turtle.pendown()


        quickshape(sides, size, thickness)


        screen.title(titlename + " [Finished drawing pattern " + str(goes) + "]")

        screen.update()


    goes += 1


screen.mainloop()

我遺漏了以下功能:


要制作一組新圖案,請(qǐng)關(guān)閉圖案頁(yè)面......但僅限于繪制時(shí)。


因?yàn)橐坏╆P(guān)閉窗口,就無(wú)法再次啟動(dòng) Python turtle。


查看完整回答
反對(duì) 回復(fù) 2023-02-15
  • 1 回答
  • 0 關(guān)注
  • 146 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)