首页 > 解决方案 > On_release 按钮​​不起作用,转换也不起作用

问题描述

我是一个完整的代码初学者,在我的代码中找不到问题。这是主文件。我想使用按钮从 MainWindow 转换到 MakeAcc 屏幕。

但按钮似乎没有响应 on_release 代码。有什么建议么?

import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager , Screen
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.properties import ObjectProperty
from kivy.graphics import Color
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.uix.button import Button


class MainWindow(Screen):
    pass


Window.clearcolor = (1, 1, 1, 1)


class MakeAcc(Screen):
    current= "login"


class WindowManager(ScreenManager):
    pass


class Op(App):
    def build(self):
        return MakeAcc()


if __name__ == "__main__":
    Op().run()

这是KV文件。我尝试复制编码器的代码以查看它是否有效并且确实有效,但我找不到我做错了什么。任何帮助将不胜感激。

WindowManager:
    MainWindow:
    MakeAcc:

<MainWindow>:
    name: "login"


    FloatLayout:

        Label:
            text: "Popeye"
            pos_hint: { "x": 0.3,"top": 1}
            font_size: 40
            size_hint: 0.35, 0.15
            color: [0,0,0,1]

        Label:
            text: "Email Address:  "
            pos_hint: { "x": 0.1,"top": 0.8}
            font_size: 30
            size_hint: 0.35, 0.15
            color: [0,0,0,1]



        TextInput:
            multiline: False
            size_hint: 0.4, 0.15
            pos_hint: {"x": 0.5, "top": 0.8}


        Label:
            text: "Password:  "
            pos_hint: { "x": 0.1,"top": 0.5}
            font_size: 30
            size_hint: 0.35, 0.15
            color: [0,0,0,1]


        TextInput:
            multiline: False
            size_hint: 0.4, 0.15
            pos_hint: {"x": 0.5, "top": 0.5}

        Button:

            text: "Submit"
            on_press:
                app.root.current = "create"
            size_hint: 0.6, 0.14
            pos_hint: {"x": 0.2, "top": 0.2}
            background_color: [0,0,0,1]



        Button:

            text: "Don't Have An Account? Create One Today!"
            size_hint: 0.4, 0.08
            pos_hint: {"x": 0.3, "top": 0.3}
            background_color: [0,0,0,1]





<MakeAcc>:
     name:"create"


     FloatLayout:
         Label:
            text: "Create An Account"
            pos_hint: { "x": 0.35,"y": 0.8}
            font_size: 40
            size_hint: 0.35, 0.15
            color: [0,0,0,1]

        Label:
            text: "Username:  "
            pos_hint: { "x": 0.1,"y": 0.6}
            font_size: 20
            size_hint: 0.35, 0.07
            color: [0,0,0,1]



        TextInput:
            multiline: False
            size_hint: 0.4, 0.07
            pos_hint: {"x": 0.5, "y": 0.6}


        Label:
            text: "Email:  "
            pos_hint: { "x": 0.1,"y": 0.5}
            font_size: 20
            size_hint: 0.35, 0.07
            color: [0,0,0,1]


        TextInput:
            multiline: False
            size_hint: 0.4, 0.07
            pos_hint: {"x": 0.5, "y": 0.5}

        Label:
            text: "Password:  "
            pos_hint: { "x": 0.1,"y": 0.4}
            font_size: 20
            size_hint: 0.35, 0.07
            color: [0,0,0,1]


        TextInput:
            multiline: False
            size_hint: 0.4, 0.07
            pos_hint: {"x": 0.5, "y": 0.4}

        Button:

            text: "Submit"
            size_hint: 0.55, 0.14
            pos_hint: {"x": 0.25, "top": 0.2}
            background_color: [0,0,0,1]
            on_release:
                app.root.current="login"
                root.manager.transition.direction = "down"

        Button:

            text: "Already Have An Account? Click Here to Login"
            size_hint: 0.4, 0.08
            pos_hint: {"x": 0.33, "top": 0.3}
            background_color: [0,0,0,1]

标签: pythonkivykivy-language

解决方案


推荐阅读