I'm not sure I understand your question so I apologise if what I'm about to say isn't related to it.
I assume you are talking about "Back", the right softkey (which is sometimes "Exit"). If so, the only way I can think of is returning the application to its previous state. For example:
import appuifw, graphics
#We create the initial state of the application:
#Now we modify this state:
#Now we assign the UI1 function to the right softkey, so that it will "take us back"