如何在python中用乌龟写下一行 [英] How to write in a next line with turtle in python
本文介绍了如何在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"循环的每次迭代都写在一个新行中,因为现在它把它写在彼此之上.
How do I make it so each iteration of the "for" cycle it writes in a new line, because right now it writes it on top of eachother.
推荐答案
一般情况下,需要使用turtle命令移动到下一行输出.具体来说,需要将X坐标返回到左边缘,并将Y坐标向下移动字体高度:
Generally, you need to use turtle commands to move to the next line of output. Specifically, you need to return the X coordinate to the left edge and move the Y coordinate down by the font height:
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()
这篇关于如何在python中用乌龟写下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文