-1
def buttonWeiterClick(y):
    def skip():
        buttonWeiterClick(1)
    if y == 1:
        x = ampel.getZustand()
        print(x,y)
        anzeigeAktualisieren(x,y)
        ampel.schalten()
        ampel2.schalten()
        fenster.after(3000, skip)
    elif y == 2:
        print("Crashed")

I got a function which calls himself constantly via an .after Statement and I want to know if and how I can end this loop for example via a Button?

  • 1
    make the loop to check for a bool variable to be true always. And then when you press a button; make that variable false. – Vicrobot Jan 16 '19 at 18:15
  • 1
    Possible duplicate https://stackoverflow.com/questions/27050492/how-do-you-create-a-tkinter-gui-stop-button-to-break-an-infinite-loop https://stackoverflow.com/questions/39555463/tkinter-how-to-stop-a-loop-with-a-stop-button/39556099 – IMParasharG Jan 16 '19 at 18:18

1 Answers1

0

You can store the result of the after function call in some variable after_id, and then in your button callback do fenster.after_cancel(after_id)

progmatico
  • 4,714
  • 1
  • 16
  • 27