2017-10-03 4 views
0

윈도우에서 텍스트 타이핑 효과를 만들려고하는데, "TypeError : 'Text'객체를 반복 할 수 없습니다. '라는 문구가 나타납니다. 나는 텍스트 변수를 사용하려고하면 그러나 형식 오류가된다, 나는 '단어'변수를 사용하는 경우GraphWin의 타이핑 효과

from graphics import * 
import sys 
from time import sleep 

window = GraphWin('Test', 1000, 700) 

text = Text(Point(500, 150), "This is just a test :P") 
words = ("This is just a test :P") 
for char in text: 
    sleep(0.1) 
    sys.stdout.write(char) 
    sys.stdout.flush() 
word.draw(window) 

Source for typing effect

텍스트는 쉘에서 온다 : 여기에 내 현재 코드입니다. iterable으로 만드는 방법이 있습니까?

답변

0

먼저 혼합되어 변수 textwords을 혼란스럽게합니다. 둘째, 당신의 Text 개체를 반복 가능하지 않습니다,하지만 당신은 3, 당신은 표준 print 호출로 sys.stdout에 전화를 대체 할 수있는 단어 '

from graphics import * 
import sys 
from time import sleep 

window = GraphWin('Test', 1000, 700) 

text = Text(Point(500, 150), "This is just a test :P") 
words = "This is just a test :P" 

# this prints to console 
for char in words: 
    sleep(0.1) 
    sys.stdout.write(char) 
    sys.stdout.flush() 

# that displays on canvas 
for idx, t in enumerate(words): 
    text = Text(Point(300+idx*20, 150), t) 
    text.draw(window) 
    sleep(0.1) 

파이썬에서`반복하면서 연속적으로 표시 할 몇을 만들 수 있습니다 :

# this prints to console 
for char in words: 
    sleep(0.1) 
    print(char, end='', flush=True)