-1

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()
river251
  • 13
  • 5
  • 2
    Both in Python and YAML indentation is part of the syntax. A small glitch like mixing tabs and spaces can break the whole program. In your case I suspect that changing to 3 spaces has removed an invisible tab that was show as 4 spaces. – Klaus D. Jan 23 '21 at 07:08
  • I restarted Pycharm (Mac), and it made me re-indent to multiples of 4 in the .kv file. But it still puts everything in the bottom left with a big window. – river251 Jan 23 '21 at 07:10
  • Have you checked your file for tabs? `grep -n $'\t' filename` – Klaus D. Jan 23 '21 at 07:17
  • You have almost certainly written code that places your widgets in the bottom left, without noticing/understanding why. Post a minimal runnable example demonstrating the problem. – inclement Jan 23 '21 at 12:50
  • Thanks for inviting me to submit code. I've reduced it to a minimum. Don't think I can do it in this comment so I have replaced the original code above with the code example. – river251 Jan 24 '21 at 15:41

1 Answers1

0

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

river251
  • 13
  • 5