簡體   English   中英

Python的烏龜colormode不起作用

[英]python turtle colormode not working

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是否高,但是請幫忙。

我測試了您的代碼,並且在Turtle 0.0.2的Python 2.7.10環境中可以正常工作。

我認為您的問題是,您要在FADE_IN_OUT傳遞參數x/5 ,並且您必須使用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中運行代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM