Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

python - Wow, changing indentation broke my program?

My little Python and Kivy script was working. Then a little lightbulb popped up with an option to do something like adjust the style, which seemed like a good idea so I did. Then, it would not run unless I changed the indent spaces to multiples of 3 in the .kv file instead of 4. I did, and suddenly the window I'm creating with a box layout was far wider, and all of the button, image, and labels were in the bottom left corner whereas before they were stacked with the label, image, and button vertically filling the window. I'd try undoing the indenting spaces to 3s, but it throws an error on any line not spaced like that. Here is the kivy code. I did not change the python code, or spaces. I know how weird this sounds but...

<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()
question from:https://stackoverflow.com/questions/65856611/wow-changing-indentation-broke-my-program

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thank you everyone. It was indeed my indentation. When the 4-line Image section in the following was corrected to four space indents, it stopped putting things in the bottom left corner, and nicely put my label, image, and button stacked vertically and taking the full width.

Thanks to you guys.....

Jim

<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()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...