我在一个屏幕上打开一个弹出窗口并按下弹出按钮进入下一个屏幕,但问题是它永远不会进入第一个屏幕的on_leave方法。在下面的代码中,第一个屏幕是“选择”,弹出窗口是' NextPopup'第二个屏幕是快速的。
有人知道吗?
提前致谢!
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.graphics.context_instructions import Color
from kivy.graphics.vertex_instructions import Rectangle
from kivy.graphics.texture import Texture
from kivy.uix.button import Button
from kivy.uix.spinner import Spinner
from kivy.uix.widget import Widget
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.popup import Popup
class NextPopup(Popup):
def __init__(self, **kwargs):
super(NextPopup, self).__init__(**kwargs)
self.PopWindow(self)
def PopWindow(self, instance):
self.popbutton = Button(size_hint=(.2,.2), pos = (100,50))
self.popup = Popup(content=self.popbutton, size_hint = (.5,.5), size = (100,100), auto_dismiss = False)
self.popbutton.bind(on_press=self.popup.dismiss)
self.popbutton.bind(on_release=app.change_screen)
self.popup.open()
self.Windowclose(self)
app.ok_btn_state = True
print 'ok-btn-status', app.ok_btn_state
app.next_btn_state = False
def Windowclose(self, instance):
app.sm.current = "fast"
#app.change_screen(self)
app.sm.switch_to('gs')
#app.ok_btn_state = False
class GradeScreen(Screen):
pass
class FastScreen(Screen):
def __init__(self, **kwargs):
super(FastScreen, self).__init__(**kwargs)
def on_enter(self, *args):
print "s"
def on_leave(self, *args):
print "s"
class LetterShape(Screen):
def __init__(self, **kwargs):
super(LetterShape, self).__init__(**kwargs)
self.remain_layout = BoxLayout(id='remain_box',orientation = 'vertical',pos_hint = {'center_y': .5, 'center_x': .775 }, size_hint= (.46, 1), color = [0,1,0,1], spacing=0)
self.add_widget(self.remain_layout)
self.btn1 = Button(background_normal = 'ok.png', background_disabled_normal = 'dok.png', border = [1,1,1,1], text='Ok!', size_hint_y=.4,size_hint_x=.4, font_size=34,
pos_hint = {'center_y': 1, 'center_x': .5 })
self.btn1.opacity = 1
self.btn1.disabled = False
self.remain_layout.add_widget(self.btn1)
self.btn1.bind(on_press=self.call_popup)
def call_popup(self, instance):
a = NextPopup()
def on_enter(self, *args):
print '...............on_enter.............'
def on_leave(self, *args):
print '..----------------------------------on leave.'
class CortestApp(App):
def __init__(self, **kwargs):
super(CortestApp, self).__init__(**kwargs)
def build(self):
self.Dialogue_state = 0
self.slider_state = False
self.ok_btn_state = False
self.next_btn_state = False
self.slider_state_counter = 0
self.counter = 0
self.sm = ScreenManager(transition=FadeTransition())
self.letter = LetterShape(name="select")
self.sm.add_widget(self.letter)
self.gradescreen = GradeScreen(name = "gs")
self.sm.add_widget(self.gradescreen)
self.fastscreen = FastScreen(name="fast")
self.sm.add_widget(self.fastscreen)
self.sm.current = "select"
return self.sm
def change_screen(self, instance):
print "-------------------------------------------clear -----------------------------------------------------------------"
#self.sm.current = "select"
app.ok_btn_state = False
app.next_btn_state = True
if __name__ == '__main__':
app = CortestApp()
app.run()
here is .kv