-1
import tkinter as tk

from tkinter import *
import os

master = tk.Tk()
listbox=Listbox(master,selectmode=MULTIPLE,width=20,height=10,font=("Calibri", 12),exportselection=0)
listbox.pack(side=LEFT,fill="y")

tk.Label(master, text="Enter Folder Path ").pack(fill=tk.X,padx=120)

e1 = tk.Entry(master,width=120)
e1.pack(fill=tk.X)

path=e1.get()
folders=sorted(next(os.walk(self.path))[1],key=int)
listbox.insert(END,*self.folders)

I am trying to load listbox with the subfolder names in a directory. While running this code following error pops up:

folders=sorted(next(os.walk(self.path))[1],key=int)
StopIteration

Can someone let me know what can be done in this case? I know this issue is coming up because of os.walk function.

martineau
  • 119,623
  • 25
  • 170
  • 301
SaEIHN
  • 17
  • 3
  • Possible duplicate of [os.walk error of unhandled stopIteration](https://stackoverflow.com/questions/37289653/os-walk-error-of-unhandled-stopiteration) – tgikal Sep 20 '19 at 14:43

1 Answers1

1

One reason this happens because the folder you're trying to walk through doesn't exist.

Try checking if the value in self.path does indeed ponit to a directory that is reachable.

lahsuk
  • 1,134
  • 9
  • 20