如何在python中使用turtle编写下一行

2024-04-26 17:57:12 发布

您现在位置:Python中文网/ 问答频道 /正文

for i in range(0, len(all_keys)):
    if i == 4:
        break

    elem = dict1[all_keys[i]]

    output = elem + ": " + str(all_keys[i])

    print(output)

    write(output, font = style, align = "right")

    del dict1[all_keys[i]]

如何使“for”循环的每一次迭代都写在新行中,因为现在它把它写在每一行的上面。你知道吗


Tags: inforoutputlenifrangekeysall
1条回答
网友
1楼 · 发布于 2024-04-26 17:57:12

通常,您需要使用turtle命令移动到下一行输出。具体来说,您需要将X坐标返回到左边缘,并将Y坐标向下移动字体高度:

from turtle import *

DICTIONARY = {'one': 'uno', 'two': 'dos', 'three': 'tres'}

FONT_SIZE = 24
STYLE = ('Arial', FONT_SIZE, 'normal')

penup()

for key, element in DICTIONARY.items():

    output = element + ': ' + key

    write(output, font=STYLE)

    goto(0, ycor() - FONT_SIZE)

mainloop()

enter image description here

相关问题 更多 >