2016-04-27 69 views
0
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" 

我想讓文本淡入淡出,但它所做的是提供有關超出範圍的錯誤消息。我被告知使用colormode(255),但它不起作用。我不確定255是高還是高,但請幫忙。蟒龜色彩模式不工作

回答

0

我測試了你的代碼,它可以在Python 2.7.10環境下使用Turtle 0.0.2正常工作。

我覺得你的問題是,你傳遞參數x/5FADE_IN_OUT,並且必須使用python 3.你得到的錯誤,

_tkinter.TclError: expected integer but got "200.0" 

抱怨接收浮動,而不是一個整數。嘗試使用Python 3的整數除法運算符//而不是單個/

例如,調用FADE_IN_OUT這樣的:

FADE_IN_OUT("47 Studios", "center", "Arial", x//5, "normal", 2.5, 2.5, 5) 

或者,嘗試運行你的代碼在Python 2

+0

非常感謝你 –