Kivy程序有一个TypeError



为什么此代码会产生错误?我遵循了教程(我认为是完美的(:

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.core.window import Window
import random
class MainApp(App):
def build(self):
label = Label(text="Remember me:/Rebecca")
self.layout = BoxLayout(orientaion='vertical',size=(Window.width, Window.height))
self.box = BoxLayout(orientation='horizontal', spacing=50, pos=(0,500))
self.txt = TextInput(hint_text="Write here",size_hint=(.5,.1))
self.box.add_widget(self.txt)
self.layout.add_widget(self.box)
self.layout.add_widget(self.label)
return self.layout
if __name__ == '__main__':
app = MainApp()
app.run()

错误:

File "C:UsersRebecca.BiAppDataLocalProgramsPythonPython37libsite-packageskivyuixwidget.py", line 350, in __init__       
super(Widget, self).__init__(**kwargs)
File "kivy_event.pyx", line 245, in kivy._event.EventDispatcher.__init__
TypeError: object.__init__() takes exactly one argument (the instance to initialize)

这个问题不能解决我的问题,因为解决方案不能解决我问题。他们推荐的东西我都试过了,但还是不行。

非常感谢您的帮助!

答案是将sizesize_hint替换为size_smallsize_large或您想要的任何其他大小。使用这些命令,您可以在kivy中指定所需的大小。

您错过了拼写为orientaion的单词。应为中的orientation

self.layout = BoxLayout(orientaion='vertical',size=(Window.width, Window.height))

您错过了拼写为orientation的内容,并在self.layout.add_widget(self.label)而不是label中传递了self.label作为参数。

label = Label(text="Remember me:/Rebecca")更改为self.label = Label(text="Remember me:/Rebecca"),它应该可以工作。

相关内容

最新更新