如何用python中的turtle写下一行

时间:2019-12-11 13:00:36

标签: python turtle-graphics

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”循环的每次迭代都写在新行中,因为现在它将其写在彼此之上。

1 个答案:

答案 0 :(得分:0)

通常,您需要使用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