我正在尝试使用屏幕管理器和.kv文件构建一个简单的Kivy(1.10.1)应用,但我一直黑屏。
我的ScreenManager(GUI / nco.py)
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager
from GUI.login import LoginScreen
class NCO(ScreenManager):
def add_widget(self, screen):
super(NCO, self).add_widget(screen)
# TODO: add a radial gradiant background from (0, 155, 190) to (0, 5, 20)
print("added screen:", screen.name)
class NCOApp(App):
def build(self):
nco = NCO()
nco.add_widget(LoginScreen(name="login"))
return nco
GUI / login.py
from kivy.uix.screenmanager import Screen
class LoginScreen(Screen):
def test(self):
mail = self.ids.mail.text.strip()
pwd = self.ids.pwd.text
print("e-mail:", mail)
print("password:", pwd)
GUI / login.kv
#:kivy 1.10.1
<LoginScreen>:
AnchorLayout:
size: self.parent.size
BoxLayout:
size_hint: None, None
size: 400, 35
orientation: "horizontal"
TextInput:
id: mail
font_size: 20
hint_text: "e-mail"
multiline: False
write_tab: False
TextInput:
id: pwd
font_size: 20
password: True
hint_text: "password"
multiline: False
write_tab: False
Button:
size_hint: .3, 1
text: "login"
on_press: root.manager.current.test()
main.py
from GUI.nco import NCOApp
from kivy.config import Config
Config.set("graphics", "fullscreen", "auto")
if __name__ == '__main__':
NCOApp().run()
当我不使用ScreenManager时,我已经成功显示登录屏幕,并且无需调用Builder.load_string()
就可以正常工作
我已经在网上搜索过,每个可行的解决方案都涉及到我不希望使用的Builder.load_string()
呼叫,这可能使其正常工作吗?