【发布时间】:2021-10-12 02:03:26
【问题描述】:
我想使用 for 循环在我的 tkinter 窗口上显示多个图像。 该窗口仅显示最后一张图像。我该如何解决? 我对 tkinter 和 python 有点陌生。 以下是我的代码:
mycursor.execute("SELECT * from Contacts ORDER BY NAME")
show_result = mycursor.fetchall()
name_list = []
contact_list = []
email_list = []
dob_list = []
category_list = []
profile_location = []
for row in show_result:
name_list.append(row[0])
contact_list.append(row[1])
email_list.append(row[2])
dob_list.append(row[3])
category_list.append(row[4])
profile_location.append(row[5])
name_length = len(name_list)
a = 200
b = 30
c = 50
imgx = 10
imgy = 20
for i in range(0, name_length):
name = name_list[i]
contact = contact_list[i]
email = email_list[i]
dob = dob_list[i]
category = category_list[i]
profile = profile_location[i]
img_open = Image.open(profile)
img_tst = ImageTk.PhotoImage(img_open)
label_name = Label(seewindow, image=img_tst)
label_name.place(x=imgx, y=imgy)
a += 200
imgx += 250
【问题讨论】:
-
尝试添加
label_name.image=img_tst -
@Sujay 不会有帮助,因为
label_name已被覆盖,因此从技术上讲它超出了范围 -
将所有
img_tsts 放在一个列表中。 -
@Sujay 谢谢你这个作品
-
@TheLizzard 它以某种方式工作,我的问题得到了解决,谢谢
标签: python image loops tkinter