0

Hello I am working on a screenshot project. For part of it I would like to open up a window with a button for every screenshot then be able to click on one and get the image to show up. I so far used this function to create the buttons when it opens the window.

def create_secondwindow_button():
    x = 1
    y = 0
    mypath = "C:\\Users\\Link\\OneDrive\\Desktop\\python stuff\\screenshot example\\All snapshot images"
    for I in listdir(mypath):
        btp = mypath +"\\"+str(I)
        print(btp)
        screenshot_snap = Button(sec_window,text = str(I), bg =  "chocolate3",activebackground = "white",padx= 80,pady =10,command =lambda: image_replacer(y))
        screenshot_snap.grid(column = 4, row = int(x),rowspan = 5,columnspan = 5,padx = 50,pady =10)
        x += 10
        if y < 3:
            y += 1

The problem is the input for all the buttons just remains at the last value of y for all of them. I need to have a variable input as the amount of images are going to be constantly changing. Does anyone know how I can solve this issue. Thanks a bunch!

link
  • 23
  • 5
  • 2
    Does this answer your question? [tkinter creating buttons in for loop passing command arguments](https://stackoverflow.com/questions/10865116/tkinter-creating-buttons-in-for-loop-passing-command-arguments) – TheLizzard May 20 '21 at 17:16
  • Solved it like a charm @TheLizzard – link May 20 '21 at 17:20

0 Answers0