如何与kivyMD同时使用kivy屏幕管理器

问题描述 投票:0回答:1

我正在用kivy制作登录注册页面,并使用kivyMD组件,在工作时,我想在用户单击“注册”按钮进入注册屏幕时更改登录页面的屏幕。为此,我正在使用kivy屏幕管理器,但它似乎无法正常工作。最初,我以普通的方式编写代码,并使用与屏幕管理器相同的逻辑,并且运行良好。请对此提供帮助。

这是我的main.py文件

from kivy.lang import Builder
from kivy.uix.screenmanager import *
from kivymd.uix.label import MDLabel
from kivymd.font_definitions import theme_font_styles
from kivymd.app import MDApp
kv=Builder.load_file('Login.kv')

class loginwindow(Screen):
    pass
class signupwindow(Screen):
    pass    
class MyScreenManager(ScreenManager):
    pass
#sm=ScreenManager()
#sm.add_widget(loginwindow(name='login'))
#sm.add_widget(signupwindow(name='signup'))

class Test(MDApp):



    def build(self):

        self.theme_cls.theme_style = "Dark"  
        screen = Screen()
        return kv



Test().run()

这是我的Login.kv文件

#: import ScreenManager kivy.uix.screenmanager.ScreenManager
#: import Screen kivy.uix.screenmanager.ScreenManager

<MyScreenManager>:
    id: sm
    loginwindow:
    signupwindow:
<loginwindow>:
    name: 'login'
    FloatLayout:
      MDTextField:
          id: username
          hint_text: "Enter Username"
           pos_hint: {'center_x': 0.5, 'center_y': 0.6}
          size_hint:(0.50, 0.10)
           color_mode: 'primary'


     MDTextField:
          id: password
          hint_text: "Enter Password"
          password:True
            pos_hint: {'center_x': 0.5, 'center_y': 0.5}
           size_hint:(0.50, 0.10)


      DefaultLabel:
          text: 'Scheduler'
          font_size: '50sp'
            pos_hint: {'center_y': 0.8}
         font_name: 'Product Sans Bold.ttf'


        MDRoundFlatButton:
           size_hint: (0.2,0.0675)
           font_size: '20sp'
            text: "Login"
         pos_hint:{'center_x':0.38,'center_y':0.37}


      MDFillRoundFlatButton:
         size_hint: (0.2,0.0675)
          font_size: '20sp'
         text: "Sign Up"
            pos_hint:{'center_x':0.62,'center_y':0.37}
          on_release:
                app.root.current = "signup"


<signupwindow>:
    name: 'signup'

    FloatLayout:
        DefaultLabel:
            text: 'Welcome to Scheduler!!'
            font_size: 60
            pos_hint: {'center_y': 0.85}
            font_name: 'Product Sans Bold.ttf'


        DefaultLabel:
            text: 'In order to use our application, please fill the following details:-'
            font_size: 20
            pos_hint: {'center_y': 0.75}


      DefaultInput:
            id: username
          hint_text: "Enter Full Name"
         pos_hint: {'center_x': 0.5, 'center_y': 0.65}


        DefaultInput:
            id: email
            hint_text: 'Enter Email ID'
            pos_hint: {'center_x': 0.5, 'center_y': 0.55}


     DefaultInput:
            id: confirm_email
            hint_text: 'Confirm Email ID'
        pos_hint: {'center_x': 0.5, 'center_y': 0.45}


     DefaultInput:
            id: password
         hint_text: "Enter Password"
           password:True
            pos_hint: {'center_x': 0.5, 'center_y': 0.35}


     DefaultInput:
           id: confirm_pass
            hint_text: "Confirm Password"
           password:True
          pos_hint: {'center_x': 0.5, 'center_y': 0.25}


        MDRoundFlatButton:
          size_hint: (0.2,0.0675)
         font_size: '20sp'
          text: "Go Back"
           pos_hint:{'center_x':0.38,'center_y':0.15}


     MDFillRoundFlatButton:
            size_hint: (0.2,0.0675)
           font_size: '20sp'
            text: "Confirm"
          pos_hint:{'center_x':0.62,'center_y':0.15}



<DefaultLabel@MDLabel>:
    theme_text_color: 'Primary'
    halign: 'center'
    font_name: 'Product Sans Regular.ttf'

<DefaultInput@MDTextField>:
    size_hint:(0.50, 0.10)

我做错什么了吗?

我也提到了KivyMD Screen Manager, cannot get working,但它似乎也不起作用

我主要遇到的错误包括:1.运行代码没有任何反应2.“必须定义应用对象”

python kivy screen
1个回答
0
投票
<signupwindow>:
    name: 'signup'

注意,所有字母均为小写,但是当您尝试更改屏幕时

app.root.current = "SignUp"

您已经将字母'S'和'U'大写了

变量/屏幕名称区分大小写-因此您必须小心使用它们

© www.soinside.com 2019 - 2024. All rights reserved.