from turtle import *
import time
ht()
setup(width=500, height=500, startx=0, starty=0)
x=0
y=0
goto(0, 0)
colormode(255)
while True:
write("Please type your screens size in pixels into the console.", move=False, align="center", font=("Arial", 10, "normal"))
x = int(input('x'))
y = int(input('y'))
if x > 0:
print('.')
if y > 0:
print('...')
break
if x==0:
x=1000
y=500
break
else:
clear()
write("Please enter a valid number (ie. x, y)", move=False, align="center", font=("Arial", 28, "normal"))
setup(width=1400, height=800, startx=100, starty=20)
clear()
def FADE_IN_OUT(arg, align, font, size, Norm, fspeedin, fspeedout, pause):
r=255
g=255
b=255
for i in range(100):
pencolor((r,g,b))
write(arg, move=False, align=align, font=(font, size, Norm))
r-=25.5
g-=25.5
b-=25.5
time.sleep(fspeedin/100)
clear()
time.sleep(pause)
for i in range(100):
pencolor((r,g,b))
write(arg, move=False, align=align, font=(font, size, Norm))
r+=25.5
g+=25.5
b+=25.5
time.sleep(fspeedout/100)
clear()
FADE_IN_OUT("47 Studios", "center", "Arial", x/5, "normal", 2.5, 2.5, 5)
#the following is the error message I receive:
Traceback (most recent call last):
File "C:/Python34/Survive.py", line 48, in <module>
FADE_IN_OUT("47 Studios", "center", "Arial", x/5, "normal", 2.5, 2.5, 5)
File "C:/Python34/Survive.py", line 33, in FADE_IN_OUT
write(arg, move=False, align=align, font=(font, size, Norm))
File "<string>", line 1, in write
File "C:\Python34\lib\turtle.py", line 3431, in write
end = self._write(str(arg), align.lower(), font)
File "C:\Python34\lib\turtle.py", line 3403, in _write
self._pencolor)
File "C:\Python34\lib\turtle.py", line 597, in _write
fill = pencolor, font = font)
File "<string>", line 1, in create_text
File "C:\Python34\lib\tkinter\__init__.py", line 2342, in create_text
return self._create('text', args, kw)
File "C:\Python34\lib\tkinter\__init__.py", line 2318, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: expected integer but got "200.0"
I am trying to make text fade in and out but all it does is gives an error message about being out of range. I've been told to use colormode(255) but it just does not work. I am unsure of whether 255 is to high or something but please help.
I tested your code and it works fine in a Python 2.7.10 environment with Turtle 0.0.2.
I think your problem is that you're passing the argument x/5
in FADE_IN_OUT
, and you must be using python 3. The error you're getting,
_tkinter.TclError: expected integer but got "200.0"
is complaining about receiving a float instead of an integer. Try using Python 3's integer division operator //
instead of a single /
.
For example, call FADE_IN_OUT
like this:
FADE_IN_OUT("47 Studios", "center", "Arial", x//5, "normal", 2.5, 2.5, 5)
Or, try running your code in Python 2.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.