jarvisteach / appJar

Simple Tkinter GUIs in Python
http://appJar.info
Other
615 stars 68 forks source link

If you add in `self.setStopFunction(f)`, the program will not end unless `f()` contains some form of `sys.exit(0)` #521

Closed robertmlinden closed 6 years ago

robertmlinden commented 6 years ago

See subj. line

robertmlinden commented 6 years ago

I would like a way to run statements after app.launch(), specifically restart the app. If you have any suggestions regarding this process (considering that I can't exit cleanly with a stop function...).

robertmlinden commented 6 years ago

And calling app.stop() within this stop function obviously causes infinite recursion.

jarvisteach commented 6 years ago

The purpose of .setStopFunction() is to allow you to confirm the user really wants to exit - the stop function should return True to confirm exit, or `False to prevent exit. It's common to show some kind of popup to get this confirmation.

Have you tried the code here: http://appjar.info/pythonEvents/#stopping-the-gui

I've just given it a quick test, and it seems to be working.

app.stop() is a way of quitting the GUI, it should be linked to a button, or called from within a function. If a stopFunction has been set, then app.stop() will still run the stopFunction to confirm the user wants to exit.

Here's the code I used:

from appJar import gui 

def checkStop():
    return app.yesNoBox("Confirm Exit", "Are you sure you want to exit the application?")

with gui('Stop test') as app:
    app.label('Stop Test')
    app.stopFunction = checkStop
    app.button('quit', app.stop)
jarvisteach commented 6 years ago

As to your question about running functions where the GUI starts, there is a corresponding startFunction: http://appjar.info/pythonEvents/#starting-the-gui

You use this in the same way, registering a function that will be called once the GUI has started...

jarvisteach commented 6 years ago

And, getting the program to run again once it's closed, you could try putting it in a infinite loop, although I'm not sure how that will work out...

Alternatively, just have the stopFunction always return False, that'll prevent the user from exiting...

robertmlinden commented 6 years ago

Thank you! Return true, got it.

jarvisteach commented 6 years ago

I've updated the docs :)