设置并选择要翻阅其图像的画廊 [英] setting up and choosing which gallery to flip through its images

查看:79
本文介绍了设置并选择要翻阅其图像的画廊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用键盘输入1和2进行选择,以选择图库1或2,该图库是要在屏幕上加载的图像的列表 使用此代码,可以在一个画廊中正常工作

i was trying to choose with keyboard input 1 and 2 to choose the gallery 1 or 2 which is a list of images to be loaded on the screen it worked fine with one gallery with this code

import pygame


WIDTH = 1366
HEIGHT = 768

pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.NOFRAME)
clock = pygame.time.Clock()  # Needed to limit the frame rate.
pygame.display.set_caption('Katso')
# Put the images into a list.
images = [
    pygame.image.load('assets/download.png').convert(),
    pygame.image.load('assets/mickey.jpg').convert(),
    pygame.image.load('assets/cat.jpg').convert(),
    pygame.image.load('assets/flavours.jpg').convert(),
    pygame.image.load('assets/hallway.jpg').convert(),
    ]
image_index = 0
image = images[image_index]  # The current image.

x = 0  # x coordnate of image
y = 0  # y coordinate of image

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                image_index -= 1  # Decrement the index.
            elif event.key == pygame.K_RIGHT:
                image_index += 1  # Increment the index.

            # Keep the index in the valid range.
            image_index %= len(images)
            # Switch the image.
            image = images[image_index]

    screen.fill((30, 30, 30))
    # Blit the current image.
    screen.blit(image, (x, y))

    pygame.display.update()
    clock.tick(30)  # Limit the frame rate to 30 fps.

pygame.quit()

但是尝试添加更多列表并被选中只是没有用.我试图在不同的循环和相同的循环下选择图库,但没有任何效果.

but trying to add more lists and to be picked just didnt work. i tried making the choice of gallery in a different loop and under the same loop and nothing is working.

import pygame


WIDTH = 1366
HEIGHT = 768

pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.NOFRAME)
clock = pygame.time.Clock()  # Needed to limit the frame rate.
pygame.display.set_caption('Katso')
# Put the images into a list.
gallery1 = [
    pygame.image.load('assets/download.png').convert(),
    pygame.image.load('assets/mickey.jpg').convert(),
    pygame.image.load('assets/cat.jpg').convert(),
    pygame.image.load('assets/flavours.jpg').convert(),
    pygame.image.load('assets/hallway.jpg').convert(),
    ]

gallery2 = [
    pygame.image.load('assets/adv.jpg').convert(),
    pygame.image.load('assets/star.jpg').convert(),
    pygame.image.load('assets/images.jpeg').convert(),
    pygame.image.load('assets/tile.png').convert(),
    ]

x = 0  # x coordnate of image
y = 0  # y coordinate of image

running = True
gallery = gallery1 #set the default gallery

image_index = 0
image = gallery[image_index]  # The current image.

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_1:
                gallery = gallery1
            elif event.key == pygame.K_2:
                gallery = gallery2            
            elif event.key == pygame.K_LEFT:
                image_index -= 1  # Decrement the index.
            elif event.key == pygame.K_RIGHT:
                image_index += 1  # Increment the index.

            # Keep the index in the valid range.
            image_index %= len(gallery)
            # Switch the image.
            image = gallery[image_index]

    screen.fill((30, 30, 30))
    # Blit the current image.
    screen.blit(image, (x, y))

    pygame.display.update()
    clock.tick(30)  # Limit the frame rate to 30 fps.

pygame.quit()

推荐答案

发布问题后,它终于可以工作了 我很高兴看到任何提示或想法,以改善此程序的工作方式.

I got it working finally after i posted the problem i would be glad to see any hints or ideas to improve how this program works.

import pygame


WIDTH = 1366
HEIGHT = 768

pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.NOFRAME)
clock = pygame.time.Clock()  # Needed to limit the frame rate.
pygame.display.set_caption('Katso')
# Put the images into a list.
gallery1 = [
    pygame.image.load('assets/download.png').convert(),
    pygame.image.load('assets/mickey.jpg').convert(),
    pygame.image.load('assets/cat.jpg').convert(),
    pygame.image.load('assets/flavours.jpg').convert(),
    pygame.image.load('assets/hallway.jpg').convert(),
    ]

gallery2 = [
    pygame.image.load('assets/adv.jpg').convert(),
    pygame.image.load('assets/star.jpg').convert(),
    pygame.image.load('assets/images.jpeg').convert(),
    pygame.image.load('assets/tile.png').convert(),
    ]

x = 0  # x coordnate of image
y = 0  # y coordinate of image

running = True
gallery = gallery1 #set the default gallery

image_index = 0
image = gallery[image_index]  # The current image.

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_1:
                gallery = gallery1
            elif event.key == pygame.K_2:
                gallery = gallery2                      
            elif event.key == pygame.K_LEFT:
                image_index -= 1  # Decrement the index.
            elif event.key == pygame.K_RIGHT:
                image_index += 1  # Increment the index.

            # Keep the index in the valid range.
            image_index %= len(gallery)
            # Switch the image.
            image = gallery[image_index]

    screen.fill((30, 30, 30))
    # Blit the current image.
    screen.blit(image, (x, y))

    pygame.display.update()
    clock.tick(30)  # Limit the frame rate to 30 fps.

pygame.quit()

这篇关于设置并选择要翻阅其图像的画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆