0
파이썬에서 datetime 코드를 실험하고 있었기 때문에 다른 코드를 실행하면서 한 조각의 코드에서 time.sleep 함수를 수행 할 수있었습니다. 다음은 내 코드입니다 :Pygame datetime 문제
import datetime, pygame
pygame.init()
secondtick = pygame.time.Clock()
timestr = str(datetime.datetime.now().time())
timelist = list(timestr)
timex = 1
while timex <= 6:
timelist.pop(0)
timex += 1
timex2 = 1
while timex2 <= 7:
timelist.pop(2)
timex2 += 1
secondstr1 = str("".join(timelist))
while 1:
timestr = str(datetime.datetime.now().time())
timelist = list(timestr)
timex = 1
while timex <= 6:
timelist.pop(0)
timex += 1
timex2 = 1
while timex2 <= 7:
timelist.pop(2)
timex2 += 1
secondstr2 = str("".join(timelist))
x = 1
if int(secondstr2) - x == int(secondstr1):
print(x)
x += 1
여기 결과입니다 : 나는 time.sleep를 추가 할 경우
C:\Python32\python.exe "C:/Users/depia/PycharmProjects/testing/test.py"
Traceback (most recent call last):
File "C:/Users/depia/PycharmProjects/testing/test.py", line 31, in <module>
timelist.pop(2)
IndexError: pop index out of range
Process finished with exit code 1
(1) 바로 여기에 시간을 가져온 후에 :
-- code --
time.sleep(1)
secondstr2 = str("".join(timelist))
-- more code --
이 출력은 다음과 같습니다.
C:\Python32\python.exe "C:/Users/depia/PycharmProjects/testing/test.py"
1
끝나지 않습니다. 영원히 그 것처럼 남아 있습니다. 누구든지 도와 줄 수 있습니까?
당신은 무엇을하려고합니까? 어쩌면'pygame.time'을 사용하고'time.sleep'없이 일하는 법을 배울 것입니다 – furas
저는 한 부분 만 기다리 겠지만 나머지 부분은 실행할 수 있도록하려고했습니다. 전의. 하나의 애니메이션은 다시 재생되기 전에 잠시 기다렸지 만 플레이어는 재생되는 동안 계속 움직일 수 있습니다. 모든 while 루프가있는 전체적인 부분은 시간의 초를 분리하는 것이 었습니다. 나는 파이 게임을 봤어. 파이 게임보다 다른 것을 볼 수는 없어. 시간. 괜찮아. 전체 일을 멈출거야. – DePianoman
다른 방법으로'pygame.time.get_ticks'을 사용할 수 있습니다. 1 초 (1000ms) 지연시키기 위해서는'end_time = pygame.time.get_ticks() + 1000'을 설정하고 나중에 pygame.time.get_ticks()> = end_time : do_something()' – furas