This maybe an easy question but I cannot figure out myself.
I want to show a pop-up view over my main view, selecting something on pop-up and send the selected thing back to the main view.
I made up a simple codes to show what I want to do.
By pressing a button, another small view is shown and putting some texts in a textfield and close it, I expect the texts will be put on the main view’s label. However it will not happen and only after closing the main view, I find in the console the texts are surely printed by print statement. Seems like control is not actually back to the program after closing the pop-up. How can I fix it?
import ui
class Test(ui.View):
def __init__(self, frame):
self.frame = frame
self.bg_color = 'white'
btn = ui.Button(frame=(100,100,100,30),
title='Open pop', action = self.onBtn)
self.label = ui.Label(frame=(100,200,400,30), border_width=1)
self.add_subview(btn)
self.add_subview(self.label)
def onBtn(self, sender):
self.label.text = 'calling pop'
pop = Popup()
pop.present('sheet')
self.wait_modal()
text = pop.get_text()
self.label.text = text
pop.close()
print('after get_text', text )
class Popup(ui.View):
def __init__(self):
self.frame = (100,100,400,600)
self.bg_color = '#ededed'
self.textbox = ui.TextField(frame=(100,100,200,30))
self.add_subview(self.textbox)
self.right_button_items = [ui.ButtonItem(title='close', action=lambda x:self.close())]
def get_text(self):
return self.textbox.text
if __name__ == '__main__':
w, h = ui.get_screen_size()
v = Test((0,0,w,h))
v.present('sheet')
