Android 我怎样才能直接进入下一页,并在kivy中单击按钮时调用函数?

Android 我怎样才能直接进入下一页,并在kivy中单击按钮时调用函数?,android,python-3.x,kivy,Android,Python 3.x,Kivy,我有一个应用程序,第一个屏幕上有两个按钮。我希望两个按钮都能转到下一页,同时调用各自的函数。 有人能帮我链接或代码吗。提前感谢。以下示例演示了在发布事件中使用Kivy、小部件和按钮的,以及在按下事件时使用 main.py 从kivy.app导入应用 从kivy.lang导入生成器 从kivy.uix.screenmanager导入screenmanager,屏幕 #创建两个屏幕。请注意root.manager.current:这就是 #您可以从kv控制ScreenManager。默认情况下,每个

我有一个应用程序,第一个屏幕上有两个按钮。我希望两个按钮都能转到下一页,同时调用各自的函数。
有人能帮我链接或代码吗。提前感谢。

以下示例演示了在发布事件中使用Kivy、小部件和按钮的
,以及在按下事件时使用

main.py
从kivy.app导入应用
从kivy.lang导入生成器
从kivy.uix.screenmanager导入screenmanager,屏幕
#创建两个屏幕。请注意root.manager.current:这就是
#您可以从kv控制ScreenManager。默认情况下,每个屏幕都有一个
#属性管理器,为您提供所用ScreenManager的实例。
生成器。加载\u字符串(“”)
:
菜单屏幕:
id:姓名
名称:“菜单”
设置屏幕:
id:设置
名称:“设置”
:
盒子布局:
按钮:
文本:“转到设置和调用函数abc”
发布时:
root.manager.current='settings'
root.manager.ids.settings.func_abc(self)#可选:传递按钮实例
按钮:
文本:“转到设置和调用函数xyz”
发布时:
root.manager.current='settings'
root.manager.ids.settings.func_xyz(self)#可选:传递按钮实例
:
盒子布局:
按钮:
文本:“我的设置按钮”
按钮:
文本:“返回菜单”
按:root.manager.current='菜单'
""")
#声明两个屏幕
类菜单屏幕(屏幕):
通过
类别设置屏幕(屏幕):
def func_abc(自身,实例):
打印(f“func_abc:Called from Button with text={instance.text}”)
def func_xyz(自身,实例):
打印(f“func_xyz:Called from Button with text={instance.text}”)
#创建屏幕管理器
类屏幕管理(屏幕管理器):
通过
类TestApp(应用程序):
def生成(自):
返回屏幕管理()
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
TestApp().run()

下面的示例演示了在发布时使用Kivy、小部件和按钮的
和按下时的
事件

main.py
从kivy.app导入应用
从kivy.lang导入生成器
从kivy.uix.screenmanager导入screenmanager,屏幕
#创建两个屏幕。请注意root.manager.current:这就是
#您可以从kv控制ScreenManager。默认情况下,每个屏幕都有一个
#属性管理器,为您提供所用ScreenManager的实例。
生成器。加载\u字符串(“”)
:
菜单屏幕:
id:姓名
名称:“菜单”
设置屏幕:
id:设置
名称:“设置”
:
盒子布局:
按钮:
文本:“转到设置和调用函数abc”
发布时:
root.manager.current='settings'
root.manager.ids.settings.func_abc(self)#可选:传递按钮实例
按钮:
文本:“转到设置和调用函数xyz”
发布时:
root.manager.current='settings'
root.manager.ids.settings.func_xyz(self)#可选:传递按钮实例
:
盒子布局:
按钮:
文本:“我的设置按钮”
按钮:
文本:“返回菜单”
按:root.manager.current='菜单'
""")
#声明两个屏幕
类菜单屏幕(屏幕):
通过
类别设置屏幕(屏幕):
def func_abc(自身,实例):
打印(f“func_abc:Called from Button with text={instance.text}”)
def func_xyz(自身,实例):
打印(f“func_xyz:Called from Button with text={instance.text}”)
#创建屏幕管理器
类屏幕管理(屏幕管理器):
通过
类TestApp(应用程序):
def生成(自):
返回屏幕管理()
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
TestApp().run()

欢迎来到堆栈溢出。请阅读和[How to create a Minimal,Repeatable Example](How to create a Minimal,Repeatable Example)并更新您的问题。欢迎来到Stack Overflow。请阅读和[How to create a Minimal,Repeatable Example](How to create a Minimal,Repeatable Example)并更新您的问题。什么是良好做法,在不同的文件或单个文件中有不同的屏幕?什么是良好做法,在不同的文件或单个文件中有不同的屏幕?
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen

# Create both screens. Please note the root.manager.current: this is how
# you can control the ScreenManager from kv. Each screen has by default a
# property manager that gives you the instance of the ScreenManager used.
Builder.load_string("""
<ScreenManagement>:
    MenuScreen:
        id: name
        name: 'menu'
        
    SettingsScreen:
        id: settings
        name: 'settings'
        
<MenuScreen>:
    BoxLayout:
        Button:
            text: 'Goto settings & invoke function abc'
            on_release: 
                root.manager.current = 'settings'
                root.manager.ids.settings.func_abc(self)    # optional: passing Button instance
                
        Button:
            text: 'Goto settings & invoke function xyz'
            on_release: 
                root.manager.current = 'settings'
                root.manager.ids.settings.func_xyz(self)    # optional: passing Button instance

<SettingsScreen>:
    BoxLayout:
        Button:
            text: 'My settings button'
        Button:
            text: 'Back to menu'
            on_press: root.manager.current = 'menu'
""")


# Declare both screens
class MenuScreen(Screen):
    pass


class SettingsScreen(Screen):

    def func_abc(self, instance):
        print(f"func_abc: Called from Button with text={instance.text}")

    def func_xyz(self, instance):
        print(f"func_xyz: Called from Button with text={instance.text}")


# Create the screen manager
class ScreenManagement(ScreenManager):
    pass


class TestApp(App):

    def build(self):
        return ScreenManagement()


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