-1

画像を IMG_1 に変更しない理由について何か考えはありますか? main 関数で変数を宣言しているからでしょうか。

from pygame import *
from pygame.locals import *
import pygame
import time
import os

def main():
   while 1:
      #search for image
      imageCount = 0 # Sets Image count to 0
      image_name = "IMG_" + str(imageCount) + ".jpg" #Generates Imagename using imageCount
      picture = pygame.image.load(image_name) #Loads the image name into pygame
      pygame.display.set_mode((1280,720),FULLSCREEN) #sets the display output
      main_surface = pygame.display.get_surface() #Sets the mainsurface to the display
      main_surface.blit(picture, (0, 0)) #Copies the picture to the surface
      pygame.display.update() #Updates the display
      time.sleep(6); # waits 6 seconds
      if os.path.exists(image_name): #If new image exists
         #new name = IMG + imagecount
         imageCount += 1
         new_image = "IMG_" + str(imageCount) + ".jpg"
         picture = pygame.image.load(new_image)


if __name__ == "__main__":
    main()      
4

2 に答える 2

0

imageCountループするとリセットされます。pygameすぐに置き換えられるため、他のイメージに切り替わりません。

また、現在の画像が存在するかどうかを確認してから、存在するかどうかを確認せずに次の画像に移動しようとします。

代わりに、次を試してください。

def main(imageCount=0): # allow override of start image
    while True:
        image_name = "IMG_{0}.jpg".format(imageCount)
        ...
        if os.path.exists("IMG_{0}.jpg".format(imageCount+1)):
            imageCount += 1
于 2014-02-23T10:14:38.560 に答える