python - 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]
解决方案
推荐阅读
- java - 不满意的链接错误 - 库加载,未找到条目
- php - UnexpectedValueException 无法解析版本约束 mybranch:无效的版本字符串“mybranch”
- c - Malloc 没有分配足够的内存
- visual-studio-code - 如何配置 VSCode 以使 IntelliSense 适用于 MicroPython 系统库?
- c# - 运行 dotnet publish -c Release -o out 在 ASP.NET Core 项目中构建 Dockerfile 失败
- angular - 是否有用于以角度映射数组列表的映射函数?
- java - 如何在Android中的java代码中获取主题的窗口背景和文本颜色?
- splunk - splunk 查询以连接每小时的状态代码
- python - 将 Python 转换为 Vb.Net Web 连接
- c - C - const 问题 - 错误:初始化元素不是常量