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()
这是非常容易,因为这个程序是戈纳得到大,只要我可以得到第2页显示.....我可以使用.kv文件lanauge,但这将花费我更多的时间来计算出 – user3436797
谢谢该工作和我不得不修改check_menu_press温控功能一点点回应....不只是为了获得futher devloped感谢帮助家伙 – user3436797
不使用KV语言的应用程序是短视的。它不会需要很长时间来学习,它会给你从长远来看,更干净的代码和更少的代码。 – brousch