kivy - 缩进无效,必须是8个空格的倍数,圆角按钮kivy .kv文件
问题描述
所以是的,我正在学习 kivy - “圆形按钮”,当我运行教程的程序时 --------------- 错误: https ://i.stack.imgur.com/rGhSa.png Python:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.core.window import Window
Builder.load_file("my.kv")
class MyLayout(Widget,App):
def __init__(self,*args,**kwargs):
super(MyLayout, self).__init__(**kwargs)
class AwesomeApp(App):
def build(self):
Window.clearcolor = (1,1,1,1)
return MyLayout()
if __name__ == '__main__':
AwesomeApp().run()
.kv
<MyLayout>
BoxLayout:
orientation: "vertical"
size: root.width, root.height
padding: 50
spacing: 20
Button:
text: "Hello World!"
RoundedButton:
text: "Goodbye World!"
pos_hint: {'center_x': 0.5}
size_hint: (1, .3)
#background_color: (0/255,255/255,203/255,1)
#background_normal: ''
<RoundedButton@Button>
background_color: (0,0,0,0)
background_normal: ''
canvas.before:
Color:
rgba: (0/255,255/255,203/255,1)
RoundedRectangle:
size: self.size
pos: self.pos
radius: [58]
谢谢,谁能帮忙,不喜欢这些错误,缩进错误看起来像
解决方案
您没有进行正确的缩进,您必须在文件中仅使用一种类型的缩进,但是您使用 8 个空格和 4 个空格作为缩进,这就是错误出现的原因。
在这里,我在整个代码中使用了 4 个空格作为缩进,这就是它工作正常的原因。
<MyLayout>
BoxLayout:
orientation: "vertical"
size: root.width, root.height
padding: 50
spacing: 20
Button:
text: "Hello World!"
RoundedButton:
text: "Goodbye World!"
pos_hint: {'center_x': 0.5}
size_hint: (1, .3)
#background_color: (0/255,255/255,203/255,1)
#background_normal: ''
<RoundedButton@Button>
background_color: (0,0,0,0)
background_normal: ''
canvas.before:
Color:
rgba: (0/255,255/255,203/255,1)
RoundedRectangle:
size: self.size
pos: self.pos
radius: [58]
推荐阅读
- c++ - 将 lambda 作为默认参数传递时出错
- python - 如何在 Python 中创建等值线图?
- c++ - 我可以使用 mciSendCommand 设置音量吗?
- azure - 如何在 ARM 模板中为自动化帐户设置模块?
- postgresql - 在 PostgreSQL 中为特定模式和表所有者创建表的过程是什么
- android - Android Room 不确定如何将光标转换为方法的返回类型问题
- python - Anaconda 不工作/卸载痕迹可能会阻止
- cmake - 如何在 cmake 中包含 -fPIC?
- ios - 使用 Firebase 在 iOS 上远程配置图像视图的最佳方法是什么?
- python - 尝试用 matplotlib 制作动画