问题描述
以前我使用按钮时,将**kwargs
传递到object.__init__()
很好。在我的网格中添加一个按钮后,它现在显示此错误。
[INFO ] [Logger ] Record log in C:\Users\trist\.kivy\logs\kivy_20-10-15_0.txt
[INFO ] [deps ] Successfully imported "kivy_deps.gstreamer" 0.3.1
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO ] [Kivy ] v1.11.1
[INFO ] [Kivy ] Installed at "C:\Users\trist\PycharmProjects\AndroisOS\venv\lib\site-packages\kivy\__init__.py"
[INFO ] [Python ] v3.7.0 (v3.7.0:1bf9cc5093,Jun 27 2018,04:06:47) [MSC v.1914 32 bit (Intel)]
[INFO ] [Python ] Interpreter at "C:\Users\trist\PycharmProjects\AndroisOS\venv\Scripts\python.exe"
[INFO ] [Factory ] 184 symbols loaded
[INFO ] [Image ] Providers: img_tex,img_dds,img_sdl2,img_gif (img_pil,img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.6.0 - Build 26.20.100.7263'>
[INFO ] [GL ] OpenGL vendor <b'Intel'>
[INFO ] [GL ] OpenGL renderer <b'Intel(R) HD Graphics 530'>
[INFO ] [GL ] OpenGL parsed version: 4,6
[INFO ] [GL ] Shading version <b'4.60 - Build 26.20.100.7263'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed,single mode,not docked
Traceback (most recent call last):
File "C:/Users/trist/PycharmProjects/AndroisOS/main.py",line 47,in <module>
MyApp().run()
File "C:\Users\trist\PycharmProjects\AndroisOS\venv\lib\site-packages\kivy\app.py",line 829,in run
root = self.build()
File "C:/Users/trist/PycharmProjects/AndroisOS/main.py",line 38,in build
return MyGrid()
File "C:/Users/trist/PycharmProjects/AndroisOS/main.py",line 32,in __init__
self.submit = Button(text="Next",fontsize=40)
File "C:\Users\trist\PycharmProjects\AndroisOS\venv\lib\site-packages\kivy\uix\behaviors\button.py",line 121,in __init__
super(ButtonBehavior,self).__init__(**kwargs)
File "C:\Users\trist\PycharmProjects\AndroisOS\venv\lib\site-packages\kivy\uix\label.py",line 318,in __init__
super(Label,self).__init__(**kwargs)
File "C:\Users\trist\PycharmProjects\AndroisOS\venv\lib\site-packages\kivy\uix\widget.py",line 350,in __init__
super(Widget,self).__init__(**kwargs)
File "kivy\_event.pyx",line 243,in kivy._event.Eventdispatcher.__init__
TypeError: object.__init__() takes no arguments
Process finished with exit code 1
我从看起来像这样的文件中收到此错误(我的问题仅在使用Button时发生。)
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
class MyGrid(GridLayout):
def __init__(self,**kwargs):
super(MyGrid,self).__init__(**kwargs)
self.cols = 1
self.add_widget(Label(text="What is your EAVE/PURLIN width?"))
self.Metal = TextInput(multiline=False)
self.add_widget(self.Metal)
self.submit = Button(text="Next",fontsize=40)
self.add_widget(self.submit)
class MyApp(App):
def build(self):
return MyGrid()
if __name__ == "__main__":
MyApp().run()
解决方法
似乎您将错误的参数传递给Button
构造函数。它期望字体大小由font_size
参数指定,但是您使用的是fontsize
,而没有下划线。试试:
self.submit = Button(text="Next",font_size=40)
通常,当您使用错误的参数调用函数时,您会收到一条更有用的错误消息。这是Kivy的次要失败之处,在这种情况下它的错误消息是如此无用。