I have included the code below, the final button always works but the buttons apart from the last one don't show the image and don't let me interact with them.
def build_gui(driver,posts):
top = tkinter.Tk()
top.title("Choose the post")
prompt = tkinter.Label(text="Please select the post you would like to delete comments from: \n ")
prompt.pack()
i = 1
for post in posts:
path = post.get_image()
im = Image.open(path)
newsize=(100,100)
im = im.resize(newsize)
ph = ImageTk.PhotoImage(im)
btn = tkinter.Button(top, image = ph, command = lambda:[check_comments(driver,post),top.destroy]).pack()
top.mainloop()
return posts