[英]Why does using __init__(self, **kwargs) return the following error code: SyntaxError: invalid syntax?
I try to run the code of my Kivy app, but things go wrong when I'm creating a new class.我尝试运行我的 Kivy 应用程序的代码,但是当我创建一个新类时出现问题。 This is the code for it:
这是它的代码:
class MyGrid(GridLayout):
def __init__(self, **kwargs):
super(MyGrid, self).__init__(**kwargs)
self.cols = 2
self.add_widget(Label(text="First Name: "))
self.name = TextInput(multiline=False)
self.add_widget(self.name)
The code doesn't work because of an error in the second line with def __init__(self, **kwargs)
.由于第二行 def
__init__(self, **kwargs)
中的错误,代码不起作用。 The code returns:代码返回:
SyntaxError: invalid syntax.
I don't know what's wrong with the syntax.我不知道语法有什么问题。 What could be going wrong?
可能出什么问题了?
For anyone coming from Tech with Tim's Video, being confused as to why this happens, there is a Typo beneath Class MyGrid(GridLayout):
对于任何来自 Tech 和 Tim's Video 的人来说,对于为什么会发生这种情况感到困惑,在
Class MyGrid(GridLayout):
下面有一个错字Class MyGrid(GridLayout):
There needs to be a space between def
and __init__
. def
和__init__
之间需要有一个空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.