Problem when trying to reposition images in the BoxLayout in the Kvlang

71 views
Skip to first unread message

Gustavo Sales

unread,
Aug 3, 2019, 10:49:14 AM8/3/19
to Kivy users support

I'm creating an app with Kivy and I want it to have a header with an Image at the left corner and some buttons like a menu on this Image's right side. The problem is that I can't reposition the Image. I'm able to resize it but its position is always on the starting position of the BoxLayout.

I've tried changing its position with pos_hint and pos. Also tried resizing the Image with size_hint or setting size_hint to (None, None) and them tried to change its position again and none of them works. I've also added some buttons on the ScrollView below it that when pressed show the Image's position to check if something works. Here is the Kvfile, I'm just pasting the Screen(SomeScreen) widget where this problem is ocurring

<SomeScreen>:
    BoxLayout:
        orientation: 'vertical'
        BoxLayout:
            id: box
            size_hint: 1, 0.12
            canvas:
                Rectangle:
                    size: self.size
                    pos: self.pos
            Image:
                id: img
                size_hint: None, 0.9
                width: 200
                pos: 200, 600
                allow_stretch: True
                source: 'image.png'


        ScrollView:
            id: scr
            BoxLayout:
                orientation: 'vertical'
                size_hint: 1, None
                height: self.minimum_height
                Button:
                    size_hint: None, None
                    width: 400
                    height: 200
                    on_press: print(f'image size: {img.size}, image postion {img.pos}')
                Button:
                    size_hint: None, None
                    width: 400
                    height: 200
                    on_press: print(box.size, box.pos)
                Button:
                    size_hint: None, None
                    width: 400
                    height: 200
                    on_press: print(scr.size, scr.pos)

I'd like to change the image's position to whatever I choose

Elliot Garbus

unread,
Aug 3, 2019, 5:07:29 PM8/3/19
to kivy-...@googlegroups.com

I’m not certain if this is what your looking for, but it should help you on your way. 

I put a label in a horizontal BoxLayout, next to the image.  The layout will size the widgets.  I provided some size hints (size_hint_x) to adjust the relatives sizes of the label and the button.  If you remove the text from the label, it will serve just a place holder in the layout.

 

Change the image source back the image file you were using and give this a try.

A few recommendations: 

In the kivy examples folder the kivy catalog is a great interactive tool for exploring some simple layouts.  It is really very helpful when your learning.

 

When you are doing an initial layout I find it is easy to start the layout with all buttons.  It is easy to see the space they take up, and easy to have them report their size and position if something is wrong.

 

I have attached the KV file.  Let me know if this helps or if you have more questions.  Understanding the way layouts work fundamental to being productive in kivy.  They are a very powerful concept – but a little confusing when you’re starting out.

 

 

BoxLayout:
   
orientation: 'vertical'
   
BoxLayout:
       
Image:
           
id: img
           
allow_stretch: True
           
source: 'Actions-media-playback-start-icon - Copy.png'
           
size_hint_x: .2
       
Label:
           
text: "I'm a placeholder to size your image, delete the text and I disappear"
           
size_hint_x:.8
   
BoxLayout:
       
id: box
       
size_hint: 1, 0.12
       
canvas:
           
Rectangle:
                
size: self.size
                pos
: self.pos

   
ScrollView:
       
id: scr
       
BoxLayout:
           
orientation: 'vertical'
           
size_hint: 1, None
           
height: self.minimum_height
           
Button:
               
size_hint: None, None
               
width: 400
               
height: 200
               
on_press: print(f'image size: {img.size}, image position {img.pos}')
           
Button:
               
size_hint: None, None
               
width: 400
               
height: 200
               
on_press: print(box.size, box.pos)
           
Button:
               
size_hint: None, None
               
width: 400
               
height: 200
               
on_press: print(scr.size, scr.pos)

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b18ef07d-a716-454e-a3c0-701b20338ee6%40googlegroups.com.

 

handy.kv
Reply all
Reply to author
Forward
0 new messages