Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PIL Image.Open导致递归错误_Python_Image_Tkinter_Python Imaging Library - Fatal编程技术网

Python PIL Image.Open导致递归错误

Python PIL Image.Open导致递归错误,python,image,tkinter,python-imaging-library,Python,Image,Tkinter,Python Imaging Library,我写了一个程序,在其中的一部分,我显示了一系列图像作为输出,你可以用下一个/上一个按钮在它们之间移动 每次单击next/prev时,单击dict会更新到下一个图像的正确路径,然后运行以下代码: def set_image(): wordvar.set("Word: "+str(click_dict['curr_word'])) word_found_var.set("Word Count: "

我写了一个程序,在其中的一部分,我显示了一系列图像作为输出,你可以用下一个/上一个按钮在它们之间移动 每次单击next/prev时,单击dict会更新到下一个图像的正确路径,然后运行以下代码:

        def set_image():
            wordvar.set("Word: "+str(click_dict['curr_word']))
            word_found_var.set("Word Count: " + str(click_dict['cnt_appearances']))
            tot_word_found_var.set("Total Found Count: 
                        "+str(click_dict['curr_index']+1)+"/"+str(click_dict['tot_cnt_appearances']))
            filelbl_var.set("File: " + click_dict['curr_file'] + " Page: " + 
                        str(int(click_dict['curr_page'])+1))
            im = Image.open(click_dict['curr_directory'] + "//" + click_dict['curr_filename'])
            zoom = 0.9
            while im.size[0] >= 700:
                x = im.size[0]
                y = im.size[1]
                im = im.resize((round(x * 0.98), round(y * 0.98)))
            photo = ImageTk.PhotoImage(im)
            im.close()
            image.config(image=photo)
            output_window.mainloop()
一切都很完美,它在图像之间移动并更新StringVar,但最终在80-100张图片之间移动后,我遇到了以下错误:

  File "C:/Users/dor27/Desktop/Webber/tryy (1).py", line 46, in set_image
    im = Image.open(click_dict['curr_directory'] + "//" + click_dict['curr_filename'])
  File "C:\Python38\lib\site-packages\PIL\Image.py", line 2916, in open
    im = _open_core(fp, filename, prefix)
  File "C:\Python38\lib\site-packages\PIL\Image.py", line 2897, in _open_core
    result = not accept or accept(prefix)
  File "C:\Python38\lib\site-packages\PIL\BmpImagePlugin.py", line 50, in _dib_accept
    return i32(prefix[:4]) in [12, 40, 64, 108, 124]
  File "C:\Python38\lib\site-packages\PIL\_binary.py", line 57, in i32le
    return unpack_from("<I", c, o)[0]
RecursionError: maximum recursion depth exceeded while calling a Python object
Fatal Python error: Cannot recover from stack overflow.
Python runtime state: initialized
文件“C:/Users/dor27/Desktop/Webber/tryy(1.py)”,第46行,在set_图像中
im=Image.open(单击dict['curr\u directory']+“/”+单击dict['curr\u filename']))
打开文件“C:\Python38\lib\site packages\PIL\Image.py”,第2916行
im=_open_core(fp、文件名、前缀)
文件“C:\Python38\lib\site packages\PIL\Image.py”,第2897行,在\u open\u core中
结果=不接受或接受(前缀)
文件“C:\Python38\lib\site packages\PIL\BmpImagePlugin.py”,第50行,在
在[12,40,64,108,124]中返回i32(前缀[:4])
i32le中的第57行文件“C:\Python38\lib\site packages\PIL\\u binary.py”

返回unpack_from(“路径有效吗?与其硬编码,不如尝试为路径分配一个变量,并将其传递到
Image.open()
是的,路径有效,并且当前打开所有图像。唯一的问题是,在我在图像之间移动后(即使在两个图像之间来回移动,效果也很好),最终我遇到了这个递归错误。你在while循环中重新分配了名称
im
,那么你关闭的是什么呢?我认为python应该垃圾收集没有引用的任何对象,但我不知道Pillow如何处理打开的图像。。。