将图像对象与屏幕位置坐标配对 -- python

pairing image object with screen position coordinates -- python

我正在使用 Python 构建游戏。为了跳过细节并直接跳到问题中,我每次在屏幕上的随机位置显示 3 张图像。

......
position1 = (250,0)
position2 = (0,0)
position3 = (-250,0)

all_combinations = list(itertools.permutations([position1, position2, position3]))
random.shuffle(all_combinations)

for combination in all_combinations:
    image1 = stimuli.Picture('images\image1.png', position=combination[0])
    image2 = stimuli.Picture('images\image2.png', position=combination[1])
    image3 = stimuli.Picture('images\image3.png', position=combination[2])
....

稍后在代码中我将在屏幕上显示这些图像。玩家必须使用键盘选择一张图片。我如何将每个图像与其屏幕坐标位置配对,因为每次都是随机的?最终目标是:如果 image1 在左边,他们按下左按钮说“如果选择了 image1 ... 执行此操作”,但我找不到指定哪个图像在左边的方法。

谢谢!

我不知道你为什么要使用 permutationshuffle 如果你只需要 shuffle

我会打乱文件名并保持相同顺序的位置,然后第一张图片会在左边,因为它具有最小的 x (-250)

positions = [(-250,0), (0,0), (250,0)]

filenames = ['images\image1.png', 'images\image2.png', 'images\image3.png']
          
random.shuffle(filenames)

images = []

for name, pos in zip(filenames, positions):
    img = stimuli.Picture(name, position=pos)
    images.append( img )
    
left_img  = images[0]
left_pos  = positions[0]
left_name = filenames[0]

center_img  = images[1]
center_pos  = positions[1]
center_name = filenames[1]

right_img  = images[2]
right_pos  = positions[2]
right_name = filenames[2]