我是kivy的新手,并且使用了一些教程,但我只是在视频开发人员在屏幕上获取他们的小部件时才会出现黑屏。我尝试了多种解决方案,但我真的不明白问题所在。我想在这里建立一个登录界面是我写的代码:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
class LoginScreen(BoxLayout):
def __int__(self, **kwargs):
super(LoginScreen,self).__int__(**kwargs)
sm=ScreenManager
Screen=Screen(name="screen")
layout=BoxLayout(orientation='vertical')
self.Username = TextInput(multiline=False)
self.Password = TextInput(multiline=False, password=True)
layout.add_widget(Label(text="username"))
layout.add_widget(self.Username)
layout.add_widget(Label(text="password"))
layout.add_widget(self.Password)
Screen.add_widget(layout)
sm.add_widget(Screen)
return sm
class simplekivy(App):
def build(self):
return LoginScreen()
if __name__ == "__main__":
simplekivy().run()
感谢您的帮助!
答案 0 :(得分:0)
您的代码有以下错误:
__init__
,不称为__int__
。Screen=Screen(name="screen")
。from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
class LoginScreen(Screen):
def __init__(self, *args, **kwargs):
super(LoginScreen,self).__init__(*args, **kwargs)
layout=BoxLayout(orientation='vertical')
self.Username = TextInput(multiline=False)
self.Password = TextInput(multiline=False, password=True)
layout.add_widget(Label(text="username"))
layout.add_widget(self.Username)
layout.add_widget(Label(text="password"))
layout.add_widget(self.Password)
self.add_widget(layout)
class Manager(ScreenManager):
def __init__(self, *args, **kwargs):
super(ScreenManager,self).__init__(*args, **kwargs)
self.add_widget(LoginScreen())
class simplekivy(App):
def build(self):
return Manager()
if __name__ == "__main__":
simplekivy().run()