2017-06-29 9 views
0

Je rencontre beaucoup de problèmes en essayant d'ajouter une image à Scatter dans Kivy. Je veux que l'image apparaisse d'abord à la même hauteur que la boxlayout. Ensuite, je voudrais être en mesure de déplacer et de l'échelle (cela fonctionne actuellement). Quand je cours le code l'image se montre très petite. Je voudrais aussi que l'image se redimensionne si la taille de la fenêtre est modifiée. Je suis nouveau à Kivy donc toute aide serait géniale. Merci!Problèmes avec Kivy Scatter, Taille et position de l'image

<MyGridLayout>: 
rows: 1 

BoxLayout: 
    id:layout1 
    orientation: 'vertical' 

    BoxLayout: 
     id: box1 
     size_hint : [1,0.5] 

     StencilView: 
      ScatterLayout: 
       center_x: box1.center_x 
       center_y: box1.center_y 

       Image: 
        source: 'histo_test.png' 
        size_hint_y: None 
        size_hint_x: None 
        width: self.parent.width 
        height: self.parent.width/self.image_ratio 
        center: self.parent.center 
        allow_stretch: True 
        keep_ratio: True 




    BoxLayout: 
     size_hint : [1,0.5] 
     id:box2 

     StencilView: 
      ScatterLayout: 
       center_x: box2.center_x 
       center_y: box2.center_y 

       Image: 
        source: 'flower.png' 
        size_hint_y: None 
        size_hint_x: None 
        width: self.parent.width 
        height: self.parent.width/self.image_ratio 
        center: self.parent.center 
        allow_stretch: True 
        keep_ratio: True 

Répondre

0

La taille de l'image doit être la taille de la StencilView, de sorte que:

size: stencil.width, stencil.height 

ou

width: stencil.width 
height: stencil.width/self.image_ratio 

(stencil est l'ID de la StencilView)

Et la taille de ScatterLayout doit être la taille de l'image:

size: my_image.size 

(mon_image est l'ID de l'image)

vous pouvez également définir la position de la ScatterLayout avec la position du StencilView:

pos: stencil.pos 

au lieu de ceci:

center_x: box1.center_x  
center_y: box1.center_y 

Voir this video pour mo re info.


j'ai écrit ce code qui fait presque la même

<MyGridLayout>: 
    orientation: 'vertical' 
    StencilView: 
     id: stencil1 
     Scatter: 
      pos: stencil1.pos 
      size: my_image1.size 
      Image: 
       id: my_image1 
       size: stencil1.width, stencil1.height 
       source: 'dog.jpg' 
       allow_stretch: True 
       keep_ratio: False 
    StencilView: 
     id: stencil2 
     Scatter: 
      pos: stencil2.pos 
      size: my_image2.size 
      Image: 
       id: my_image2 
       size: stencil2.width, stencil2.height 
       source: 'flower.jpg' 
       allow_stretch: True 
       keep_ratio: False 

Désolé si mon anglais est pas clair

+0

Merci beaucoup! Cela a fonctionné parfaitement – jrx3ctl