我需要设置一个Button
,当按下输入按钮时,我可以使用Screen
语言返回.kv
。以下是我在Python中的内容:
def build(self):
button = Button()
start(Enter, button)
bind(on_press = partial(sm.setter('current'), (sm, 'MenuScreen')))
如果在.kv / kivy lanaguage中按下'Enter'键,我如何制作允许我返回页面的Button
?
答案 0 :(得分:0)
That's quite a weird syntax you have up there and you talk about "Enter key" although the code obviously does something completely different, so I think you want just this little piece:
<Enter>:
on_press: sm.current = 'MenuScreen'
These lines require an additional class Enter
to exist i.e. you wouldn't do this (and I'm confused by that line):
start(Enter, button)
but you would do for example this:
.py
class Enter(Button):
pass
class My(App):
def build(self):
pass
.kv
ScreenManager:
id: sm
Screen:
name: 'OtherScreen'
Enter:
Screen:
name: 'MainScreen'
<Enter>:
on_press: sm.current = 'MainScreen'