0
我正在尝试在pygame
中构建移动界面。我有一个名为apps的文件夹,每个应用程序都包含两个文件:“app.py
”和“app.png
”。目前我可以获取应用程序名称的文件夹内容。文件内容保存在一个数组中。我试图从每个文件夹中获取“app.png
”并将其添加到pygame
屏幕?如何根据数组的路径参加pygame窗口的图像?
这里是我当前的代码:
from pygame import *
import os
import pygame
import time
import random
_image_library = {}
class SeedOS():
def home(self):
def get_image(path):
global _image_library
image = _image_library.get(path)
if image == None:
canonicalized_path = path.replace('/', os.sep).replace('\\', os.sep)
image = pygame.image.load(canonicalized_path)
_image_library[path] = image
return image
(width, height) = (240, 320)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Seed OS')
BLACK = (0,0,0)
screen.fill(BLACK)
apps = os.walk("apps").next()[1]
app_count = 0
while app_count < len(apps):
print apps[app_count]
icon_width = 0
icon_height = 0
screen.blit(get_image("apps/" + apps[app_count] + "/app.png"), (icon_width, 0))
icon_width+=70
app_count += 1
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
phone = SeedOS()
phone.home()