首页 > 解决方案 > 哇,改变缩进破坏了我的程序?

问题描述

我的小 Python 和 Kivy 脚本正在运行。然后一个小灯泡弹出了一个选项来调整样式,这似乎是个好主意,所以我做了。然后,除非我在 .kv 文件中将缩进空间更改为 3 的倍数而不是 4,否则它不会运行。我这样做了,突然间,我使用框布局创建的窗口要宽得多,并且所有按钮,图像和标签位于左下角,而之前它们与标签、图像和按钮堆叠在一起,垂直填充窗口。我会尝试将缩进空格撤消为 3s,但它会在任何没有这样间隔的行上引发错误。这是基维代码。我没有更改 python 代码或空格。我知道这听起来很奇怪,但是...

<Pat_layout>:

   BoxLayout:
      orientation: "vertical"
      size: root.width, root.height

   Label:
      id: name_label
      text:  "Get ready for exercises"
      size_hint: (1, .5)
      font_size: 32
      multiline: True

   Image:
      id: image_window
      size_hint: (1, .5)
      source: 'images/dim_1-4.jpg'

   Button:
      size_hint: (1, .5)
      font_size: 32
      text: "Next Exercise"
      on_press: root.press()

标签: pythonkivyindentationspaces

解决方案


谢谢大家。这确实是我的缩进。当下面的 4 行图像部分被纠正为四个空格缩进时,它停止在左下角放置东西,并且很好地将我的标签、图像和按钮垂直堆叠并占据了整个宽度。

谢谢各位。。。。

吉姆

<Pat_layout>:

    
    BoxLayout:
        
        orientation: "vertical"
        
        size: root.width, root.height

        

    Label:
            
        id: name_label
            
        text:  "Exercises Appear Here"
            
        font_size: 32

    
    
    Image:
            
        id: image_window
            
        size_hint: (1, .5)
            
        source: 'images/dim_1-4.jpg'

        

    Button:
            
        size_hint: (1, .5)
            
        font_size: 32
           
        text: "Press For Next Exercise"
            
        on_press: root.press()


推荐阅读