documentation index ◦ reference manual ◦ function index
Function: | ui.returns | (value): |
This function returns a function that, when called, returns the supplied value. It's best used to supply the clicked argument to the various button widgets.
This example uses ui.returns to return a simple number from ui.interact.
$ ui.vbox(xalign=0.5, yalign=0.5) $ ui.textbutton("Choice 1", clicked=ui.returns(1)) $ ui.textbutton("Choice 2", clicked=ui.returns(2)) $ ui.close() $ result = ui.interact() if result == 1: "You picked choice 1!" else: "Choice 2 was for you!"
This example uses ui.returns to return a function func
from ui.interact, and then call the function func
. This is the recommended way to have selecting a ui widget call a user function.
init python: def SpecialFunctionA(): # ... def JumpToPart2(): renpy.jump('part2') label maybe_function_time: $ ui.vbox(xalign=0.5, yalign=0.5) $ ui.textbutton("Call Special Function A", clicked=ui.returns(SpecialFunctionA)) $ ui.textbutton("Move on", clicked=ui.returns(JumpToPart2)) $ ui.close() $ func = ui.interact() $ func()
This example shows how to have a button conditionally return a value when clicked.
init: python: # This renders an empty slot in the file picker. def _render_new_slot(name, save): if save: clicked=ui.returns(("return", (name, False))) enable_hover = True else: clicked = None enable_hover = True ui.button(style='file_picker_entry', clicked=clicked, enable_hover=enable_hover) ui.hbox(style='file_picker_entry_box') if not config.disable_thumbnails: ui.null(width=config.thumbnail_width, height=config.thumbnail_height) ui.text(name + ". ", style='file_picker_old') ### file_picker_empty_slot file_picker_text # (text) The style that is used for the empty slot indicator # in the file picker. ui.text(_(u"Empty Slot."), style='file_picker_empty_slot') ui.close()