【问题标题】:How to write in a next line with turtle in python如何在python中用turtle写下一行
【发布时间】:2019-12-11 13:00:36
【问题描述】:
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”循环的每次迭代都会在新行中写入,因为现在它会将其写在彼此之上。

【问题讨论】:

  • 或许在行尾添加"\n" 会有所帮助。

标签: python turtle-graphics


【解决方案1】:

一般情况下,您需要使用 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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-22
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    相关资源
    最近更新 更多