3

so i read here that this kivy file should make my image 40x40: but all it changes is the position. How could I change the size? This needs to be in the .kv file.

code:

Kivy File

#kivy 1.7.2
Root:
    Image:
        source: 'torch.png'
        size_hint_y: None
        size_hint_x: None
        height: dp(40)
        width: dp(40)

Main Script:

from kivy.app import App
from kivy.uix.image import Image
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.core.window import Window
class Root(FloatLayout):
    pass
class RPGApp(App):
    pass
RPGApp().run()
Community
  • 1
  • 1
pianist1119
  • 319
  • 1
  • 8
  • 19

1 Answers1

5

Don't you want dp, not db? This converts from units of density independent pixels, i.e. it should remain the same 'real' size on screens with different pixel densities.

If you just want your image to be 40 pixels square, you can omit the function altogether (i.e. height: 40 and width: 40 or just size: 40, 40).

This is explained on kivy's metrics page.

inclement
  • 29,124
  • 4
  • 48
  • 60
  • still not working. Is it possible to scale the image using the pygame api? my [little image](https://www.dropbox.com/s/38cy7a15jynes7c/torch.png) is still not scaling up, its tiny in the bottom left corner. and if I had a guess its at (40, 40) – pianist1119 Feb 13 '14 at 15:58
  • If you want it to scale to larger than the real height of the image, you must also set `allow_stretch: True`. Check the [Image docs](http://kivy.org/docs/api-kivy.uix.image.html) for more information. – inclement Feb 13 '14 at 16:20
  • so how can I change the position now?? (like I said I am new to kivy. It works perfectly, and I dont need it any clearer, but using just 'position: 50, 50' doesnt seem to work. – pianist1119 Feb 13 '14 at 16:26
  • The position propery is called `pos`. You should go through the introductory guide and examples (e.g. the pong example) to see this kind of thing. – inclement Feb 13 '14 at 18:00
  • okay, i havent looked at those for a while(im actually restarting kivy). I tried position so pos will work, thanks – pianist1119 Feb 13 '14 at 20:05