Python 2.7 重定向到kivy应用程序中的新页面/UI/显示
我有下面的示例kivy应用程序,我想根据一些验证在弹出框后重定向到新页面/显示。弹出窗口结束后如何重定向到新UI/页面 例1.kvPython 2.7 重定向到kivy应用程序中的新页面/UI/显示,python-2.7,kivy,Python 2.7,Kivy,我有下面的示例kivy应用程序,我想根据一些验证在弹出框后重定向到新页面/显示。弹出窗口结束后如何重定向到新UI/页面 例1.kv AnchorLayout: anchor_x: 'center' anchor_y: 'center' Button: height: 40 width: 100 size_hint: (None, None) text: 'Click Me' on_press:
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
Button:
height: 40
width: 100
size_hint: (None, None)
text: 'Click Me'
on_press: app.process_button_click()
<PopupBox>:
pop_up_text: _pop_up_text
size_hint: .5, .5
auto_dismiss: True
title: 'Status'
BoxLayout:
orientation: "vertical"
Label:
id: _pop_up_text
text: ''
听起来你想使用ScreenManager小部件。听起来你想使用ScreenManager小部件。
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.clock import Clock
import time, threading
class PopupBox(Popup):
pop_up_text = ObjectProperty()
def update_pop_up_text(self, p_message):
self.pop_up_text.text = p_message
class ExampleApp(App):
def show_popup(self):
self.pop_up = Factory.PopupBox()
self.pop_up.update_pop_up_text('Running some task...')
self.pop_up.open()
def process_button_click(self):
# Open the pop up
self.show_popup()
# Call some method that may take a while to run.
# I'm using a thread to simulate this
mythread = threading.Thread(target=self.something_that_takes_5_seconds_to_run)
mythread.start()
def something_that_takes_5_seconds_to_run(self):
thistime = time.time()
while thistime + 5 > time.time(): # 5 seconds
time.sleep(1)
# Once the long running task is done, close the pop up.
self.pop_up.dismiss()
if __name__ == "__main__":
ExampleApp().run()