2014-04-22 97 views
0

玉傢伙我有一個問題我想點擊彈出菜單的按鈕,然後後,我點擊它必須transistion到另一個屏幕彈出....這裏是我的代碼 只是想獲得一個新的新鮮屏幕後我點擊彈出按鈕Kivy屏幕更改

from kivy.uix.popup import Popup 
from kivy.app import App 
from kivy.uix.gridlayout import GridLayout 
from kivy.uix.label import Label 
from kivy.uix.textinput import TextInput 
from kivy.uix.button import Button 
# from kivy.uix.boxlayout import BoxLayout 
# from kivy.uix.stacklayout import StackLayout 
from kivy.uix.screenmanager import ScreenManager, Screen 


class LoginScreen(GridLayout, Screen): 
    def __init__(self, sm, **kwargs): 
     super(LoginScreen, self).__init__(**kwargs) 
     self.sm = sm 
     self.cols = 2 
     self.row = 2 
     self.add_widget(Label(text='User Name', font_size='20sp')) 
     self.username = TextInput(multiline=False) 
     self.add_widget(self.username) 
     self.add_widget(Label(text='password')) 
     self.password = TextInput(password=True, multiline=False) 
     self.add_widget(self.password) 
     self.hello = Button(text="hello", on_press=lambda a: self.save(), size=(100, 100), 
          size_hint=(0.3, 0.3)) 
     self.add_widget(self.hello) 

    def save(self): 
     print("s") 
     id_name = self.username._get_text() 
     id_num = self.password._get_text() 
     if id_name == "Hendricko" and id_num == "stokkies123": 
      content = Button(text="Press Here", size=(100, 100), size_hint=(0.3, 0.3)) 
      popup = Popup(title="You May Proceed ", 
         content=content, 
         size=(50, 50), 
         size_hint=(0.3, 0.3), 
         auto_dismiss=False) 
      content.bind(on_press=lambda b: self.check_menu_press) 
      popup.open() 

    def check_menu_press(self, button, *args): 
     if button.state == 'normal': 
      self.sm.current = "SecondScreen" 


class SecondScreen(GridLayout,Screen): 
    def __init__(self, sm, **kwargs): 
     super(SecondScreen, self).__init__(**kwargs) 
     self.row = 2 
     self.cols = 2 
     self.add_widget(Label(text="hello", font_size="20sp")) 

     self.sm = sm 

    def on_touch_down(self, touch): 
     self.sm.current = "LoginScreen" 


class MyApp(App): 
    def build(self): 
     sm = ScreenManager() 
     sm.add_widget(LoginScreen(sm, name="SecondScreen")) 
     sm.add_widget(SecondScreen(sm, name="LoginScreen")) 
     return sm 




if __name__ == '__main__': 
    MyApp().run() 

回答

0

content.bind(on_press =拉姆達b:self.check_menu_press)

此lambda函數什麼都不做。你大概的意思content.bind(on_press=lambda b: self.check_menu_press(b))。我認爲這將是整潔使用functools.partial不過,如果你想這樣做事。

+0

這是非常容易,因爲這個程序是戈納得到大,只要我可以得到第2頁顯示.....我可以使用.kv文件lanauge,但這將花費我更多的時間來計算出 – user3436797

+0

謝謝該工作和我不得不修改check_menu_press溫控功能一點點回應....不只是爲了獲得futher devloped感謝幫助傢伙 – user3436797

+2

不使用KV語言的應用程序是短視的。它不會需要很長時間來學習,它會給你從長遠來看,更乾淨的代碼和更少的代碼。 – brousch