为什么此代码会产生错误?我遵循了教程(我认为是完美的(:
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)
这个问题不能解决我的问题,因为解决方案不能解决我问题。他们推荐的东西我都试过了,但还是不行。
非常感谢您的帮助!
答案是将size
和size_hint
替换为size_small
或size_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")
,它应该可以工作。