python label不显示图片,程序无响应

import io
import tkinter
import urllib.request
from PIL import ImageTk, Image

root = tkinter.Tk()
root.geometry('1920x1000+0+0')


with open('l.txt', 'r') as wenjian:
    for hang in wenjian:
        yuanshilianjie = hang.strip()
        lianjie = urllib.request.urlopen(yuanshilianjie).read()
        d = io.BytesIO(lianjie)
        p = Image.open(d)
        t = ImageTk.PhotoImage(p)
        l1 = tkinter.Label(root, image=t, width=1920, height=900)
        l1.place(x=0, y=30)
        break


def xunhuan(image_index):
    with open('l.txt', 'r') as wenjian1:
        for hang1 in wenjian1:
            global t
            yuanshilianjie1 = hang1.strip()
            a1 = urllib.request.urlopen(yuanshilianjie1).read()
            d1 = io.BytesIO(a1)
            p1 = Image.open(d1)
            t = ImageTk.PhotoImage(p1)
            l1.after(3000, lambda: xunhuan((image_index + 1) % len(yuanshilianjie1)))


xunhuan(0)

想要逐行读取l.txt中的图片链接,将其循环显示在label里,但是程序一运行就无响应,这是哪里的问题

看了下有几个地方可疑:

  1. len(yuanshilianjie1) 这里有代码问题,yuanshilianjie1是字符串,返回的是字符串长度,而不是链接数量
  2. 这段代码有点怪,定义被放在了循环内部,每次循环时都会被重新定义
    l1 = tkinter.Label(root, image=t, width=1920, height=900)
         l1.place(x=0, y=30)
    
  3. tkinter的mainloop没调用

如果有帮助,请点击一下采纳该答案~谢谢

链接:Python读取txt文件并且画出图像,在曲线label中添加上下标