注册
登录
查看:767 | 回复:12
不二
怎么将一个列表中的元素移动到另外一个列表中
发表于 2023/9/26 14:14:09
楼主

怎么将一个列表中的元素移动到另外一个列表中

洒脱
发表于 2023/9/26 14:16:01
沙发

你这样问问题不知道问的啥,有点难回答,试试列表切片?

洒脱
发表于 2023/9/26 14:20:37
板凳

]}WA0%]C1OIWR$3K)UZTCM4.png

阿黄
发表于 2023/9/26 14:22:13
4楼

b = a.copy()

洒脱
发表于 2023/9/26 14:22:43
5楼

B9$AD6[)2MM{O0}B0`}P@T8.png

不二
发表于 2023/9/26 14:24:23
6楼
label_pic_list = []
path =  D:\Python实操\抽奖系统\photos 
i = 0
y1 = 360
x1 = 300
y2 = 120
x2 = 1200
for photo in photos:
    if i == 0:
        photos_images[i] = ImageTk.PhotoImage(Image.open(photos[i]).resize((160, 160)))
        label_pic = Label(root, image=photos_images[i])
        label_pic.place(x=600,y=120,width=160,heigh=160)
    elif i == 1:
        photos_images[i] = ImageTk.PhotoImage(Image.open(photos[i]).resize((120, 120)))
        label_pic= Label(root, image=photos_images[i])
        label_pic.place(x=550, y=300, width=120, heigh=120)
    elif i == 2:
        photos_images[i] = ImageTk.PhotoImage(Image.open(photos[i]).resize((120, 120)))
        label_pic= Label(root, image=photos_images[i])
        label_pic.place(x=700, y=300, width=120, heigh=120)
    elif i   34 and i   2:
        photos_images[i] = ImageTk.PhotoImage(Image.open(photos[i]).resize((100, 100)))
        label_pic= Label(root, image=photos_images[i])
        x1 = 300 + 100 * i + 10
        if (i - 3) % 8 == 0:
           y1 = y1 +  100 + 10
           x1 = 300-90
        else:
           x1 = 300 + 100 * (i % 8) + 10
        label_pic.place(x=x1, y=y1, width=100, heigh=100)
    else:
        photos_images[i] = ImageTk.PhotoImage(Image.open(photos[i]).resize((60, 60)))
        label_pic = Label(root, image=photos_images[i])
        if (i - 35) % 8 == 0:
            y2 = y2 + 50 + 70
            x2 = 1200-55
        else:
            x2 = 1200 + 60 * (i%8) + 1
        label_pic.place(x=x2, y=y2, width=60, heigh=60)
    #print(label_pic1)
    #label_pic_list.append(label_pic1)
    i = i + 1


不二
发表于 2023/9/26 14:29:12
7楼

就是将i==0这个索引的图片存到另一个列表中,避免其在次被选中

洒脱
发表于 2023/9/26 14:31:27
8楼

就是删除索引为0的图片?

不二
发表于 2023/9/26 14:33:59
9楼

是的

洒脱
发表于 2023/9/26 14:36:37
10楼

这样直接del photos[0]即可


YF)9@CO6Q}K77X%3JOK}O$R.png

不二
发表于 2023/9/26 14:39:31
11楼

试过了

没用

第二次运行的时候还是会将图片显示出来

我也不知道为啥

立即注册站大爷用户,免费试用全部产品
立即注册站大爷用户,免费试用全部产品