我想打印一些文本,我在有关Udemy的课程的源代码文件中看到了命令“ t.print”。我想在我的项目中使用此命令来获得乐趣。如何使用?
我已经尝试通过简单地更改诸如字体大小之类的东西来执行相同的命令数百万次,这是我现在想做的大事,但是却不知道如何做。每当我输入其他内容时,我只会收到一条错误消息。
for x in range(10000):
t.pencolor("White")
t.pendown()
t.write(your_name, font = ("Arial", int( (x + 1) / 1), "bold") )
它不断告诉我更改字体大小,但我不知道如何更改。
Traceback (most recent call last):
File "/Users/ArjunR/Desktop/code 3/s03/SpiralMyName.py", line 16, in <module>
t.write(your_name, font = ("Arial", "bold") )
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/turtle.py", line 3431, in write
end = self._write(str(arg), align.lower(), font)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/turtle.py", line 3403, in _write
self._pencolor)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/turtle.py", line 597, in _write
fill = pencolor, font = font)
File "<string>", line 1, in create_text
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 2504, in create_text
return self._create('text', args, kw)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 2480, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: expected integer but got "bold"
答案 0 :(得分:0)
尝试一下:
import turtle as t
FONTSIZE = 10
FONTSTYLE = ('Arial', FONTSIZE, 'normal')
t.write('Hello World!', font=FONTSTYLE)
t.mainloop()
这是我们通常使用乌龟绘制的方式,在您使用ramge(10000)的情况下,它肯定不是valod字体,请尝试缩小范围。