How to show a value choosen in previous UI.
I would like to know how to use common value between multiple UI screen.
For example, when a user chooses something option in a top page, I want to display the value on next page as a default value. In my recogntion, to set value to a variable, we need to catch something event from pushing bottom or something.
But I want to show a value choosen in previous screen as a default value in next screen.
Could you please give me a advice to implement my hope.
mikael last edited by
Buttons call their
actionwhen pressed. TextViews have the value in the
textproperty, which you can copy when moving to the next screen. Other elements have other ways of reacting to user input. All of these are described in the in-app docs.
If that does not help, please share the code you have and we can provide more specific suggestions.
johnridesabike last edited by johnridesabike
Depending on what you're trying to do, a function like this might be what you need. For this code to work, you would have a button's action set to
new_viewhas a text field that you want to be set to the button's title. You can modify the details to fit your specific UI.
def button_open_view(sender): # gets called when user selects an option from the first view new_view = ui.load_view('new_view') new_view['textfield'].text = sender.title new_view.present()
yoyo last edited by ccc
#This is a sample code based on my app. import ui Import random #This function is connected to a button in TopPage.pyui def screen_front(sender): key = random.randrange(0,20,1) v3.bring_to_front() # I would like to show ‘key’ value in Next.pyui as default value after # ‘v3.bring_to_front()’ execution. It means that key value in Next.pyui # is always different since a value of key is set with random method. v1 =ui.load_view('Canvas') v2 =ui.load_view('TopPage') v3 =ui.load_view('Next') v1.add_subview(v2) v1.add_subview(v3) #Bring TopPage.pyui as top page UI. v2.bring_to_front() v1.present('sheet')
@johnridesabike I have tried your sample code. However, load_view generate new screen, right? What I want to do is to change screen without exit button located on title bar...
@johnridesabike Based on your sample, I was able to implement my requirement! Thank you so much.