0

I have a logical problem with tkinter: I have piece of code where a for loop iterates trough an Excel file. But at every iteration you should press a button to execute some code and go to the next iteration. Here I have my piece of code:

def name_of_function():
    for i in range(1, ws.max_row + 3):
        ana = ws.cell(row=i, column=2).value
        num = str(ws.cell(row=i, column=1).value)
        anu = str(ws.cell(row=i, column=3).value)
        if ana != None:
            ana = ana[:17] + "\n" + ana[17:34] + "\n" + ana[34:]

        num_and_anu_label.config(
            text="Locatienummer= " + num + 4 * "\n" + "Artikelnummer= " + anu + "\n Artikelnaam= " + ana)

        ana_text.insert('end', ana)

        z = False

        while z == False:
            def go_to_next():
                z = True
                return (z)

        go_to_next_button = Button(button_frame, text="volgende", command=lambda: go_to_next)
        go_to_next_button.grid(row=5, column=2, pady=20)
        # run some code

When I press the button in my Tkinter app, it does nothing except loading and loading!

Could anyone please help?

  • your code doesn't move past `while z == False:` (which btw can be shortened to `while not z:`) and given the circumstances it never will, there is nothing that changes the state of `z` so it will always loop (until the process is killed), you have to learn about event-driven architectures, you can't just have loops in your code (unless they are fast and stuff) – Matiiss Jan 03 '22 at 20:38

0 Answers0