Home > Back-end >  End a running function using inner function with tkinter input GUI form, and display a warning messa
End a running function using inner function with tkinter input GUI form, and display a warning messa

Time:10-27

I want the f2 to end not itself, but rather completely the parent function f1 while being executed, with a command. I know that return is used to end a function, but it doesn't work here at a sub-level.

So my question is what are these commands (or sets of lines) and how can I implement them in my code? Example snippet here:

def f1:
    do something
    def f2:
        do something
        # need a command here
    f2()
    do something

f1()

It is noteworthy that the code shall be running a while True: loop at the time of discontinuing function. I used tkinter library button to execute a sub function (which means that the sub-function cannot return a value to a variable), but am unable to end the main function from within that set of code.

here is the tkinter code:

tk.Button(root, text='Click me', command=f2)

Here command = f2 executes f2() when tk.Button is pressed, but the value is not returned anywhere. Probably a local or global variable flag can be used inside f2...

Way to quit the most outer function from an inner function? -- This doesn't solve my problem since I must not define a class or error in my code. Is there another method to do so?

EDIT: I think I am unable to convey the problem I am facing properly.

At this point it is just a mess

  • Related