-1

I am creating a search function in my tkinter program and I have a problem with empty widgets getting packed if the ifstatement where the widgets should get packed in is false.

I try to explain what I am trying to do: I have a while loop which is looping through all files in a folder. In the while loop is a if statement which checks if the filename contains the searched letters. If yes, a Label with the filename will be packed. If no, nothing should happen. But when the filename doesn´t contain the searched letters, a empty widget is been packed.

Here is a short example of my code:

whileLoop = True
search = Entry(root)
fileNameList = ["abc","def","ghi"]
whileLoopCounter = 0

while whileLoop == True:
   if search in fileNameList[whileLoopCounter]:
      Label(root, text=fileNameList[whileLoopCounter])
      whileLoop = False
   whileLoopCounter += 1

This is a very short version of my code, because the real code would be way to long. But I hope you understand what I am trying to do.

Thanks for your help.

Whoozy
  • 161
  • 17

1 Answers1

1
search = Entry(root)
fileNameList = ["abc","def","ghi"]
for d in fileNameList:
    if d in search.get():
        Label(root, text=d)

try this! it uses "any". Also you need to do "in" on 'each' string not on the whole list!