我正在尝试实现我用kivy编写的游戏的图形部分。由于我是kivy的新手,所以我查阅了ts文档,我找到了一些我研究和使用的编程示例。在其中一个示例中,我得到:
TypeError: object.__init__() takes no parameters代码如下:
from kivy.app import App;
from kivy.uix.label import Label;
from kivy.uix.gridlayout import GridLayout;
from kivy.uix.textinput import TextInput;
class LoginScreen(GridLayout):
def __init__(self, **kwargs):
#super(LoginScreen, self).__new__(**kwargs) # == super(LoginScreen, self).__init__(**kwagrs)
#GridLayout.__init__()
super().__init__(**kwargs);
self.cols = 2 # The colors
# Creating the Object for username and then adding it into Canvans
self.add_widget(Label(text="Username: "))
self.username = TextInput(multiline=False)
self.add_widget(self.username)
# Creating the Object for password and then adding it into Canvans
self.add_widget(None,Label(Text="password:"))
self.password = TextInput(password=True,multiline=False)
self.add_widget(self.password)
class SimpleKivy(App):
def build(self):
return LoginScreen();
if __name__ == "__main__":
SimpleKivy().run();发布于 2017-10-09 05:34:29
错误在这一行上:
self.add_widget(None,Label(Text="password:"))您不需要使用None,并将Text=更改为text=,因为kivy的关键字args都是小写的。因此,将其更改为:
self.add_widget(Label(text="password:"))另外,也可以看看Kv language,它对于使用kivy构建应用程序非常有用。
https://stackoverflow.com/questions/46635051
复制相似问题