Pausing a TKinter button creation loop until a button is pressed

Hi all,

I am creating a program with TKinter that creates interactive buttons on specific locations over an image. If a button is clicked for the first time its coordinates are added to a list, and if it is clicked a second time it is removed from this list.

My issue is that I do not want these buttons to be displayed at the same time. For example: I want the total amount of buttons to be displayed in 4 batches - I display the first quarter of the buttons and when the user clicks a button in the GUI, these buttons are removed and the next quarter is displayed. So far the only solution I have found is to use “input(“Press Enter to continue…”)”, but this is not really feasible since you need to press the button in the terminal, not in the GUI itself.

How should I approach this to handle the “pause” in the GUI itself?

def create_screw_buttons(screws_per_lid): #Creates a dictionary of buttons that are displayed on top of the screw coordinates

    i = 0
    x = 0
    lid = 1
    lid_dict = {}

    co_list.sort(key=lambda x: x[0])
    
    while i < len(co_list):

        screw_dict["Button" + str(i)] = tk.Button(root, image = button_up, activebackground = "blue", command = lambda i = i: change_button(co_list, chosen_screw_list, i))
        screw_dict["Button" + str(i)].place(x = 50 + image.width()/prt_size[0][0] * co_list[i][0]-button_size[0], y = image.height()/prt_size[0][1] * co_list[i][1]-button_size[1])
        root.update_idletasks()

        if x == screws_per_lid or i == len(co_list)-1:            

            lid_dict["Button" + str(lid)] = tk.Button(root, text = 'Choose screws that are not part \n of the LID. Click button once finished')
            lid_dict["Button" + str(lid)].pack()
            lid_dict["Button" + str(lid)].place(x = width/2, y = 160,  height=50, width=250)

            if lid > 1:

                lid_dict["Button" + str(lid)].place_forget()

            if i > screws_per_lid*2-1:
                
                y = 0

                for y in range(i-screws_per_lid-20):
                    
                    screw_dict["Button" + str(y)].place_forget()

            input("Press Enter to continue...")
            
            z = 0
            x = 0
            lid =+ 1