Reputation: 6641
In my app I need to know how big the canvas is in pixels.
Instead calling canvas.size
returns [100,100]
no matter how many pixels the canvas is wide.
Can you please tell me a way to get how many pixels the canvas is wide and high?
Upvotes: 2
Views: 6988
Reputation: 1
It seems that the canvas has a "size" of (100,100) whatever you do. The size you are looking for must be the widget size e.g. If you have a FloatLayout and want to draw on it a rect that fills it try:
f = FloatLayout
Rectangle(pos_hint={'x': 0, 'y': 0}, size=f.size)
and not
Rectangle(pos_hint={'x': 0, 'y': 0}, size=f.canvas.size)
Upvotes: 0
Reputation: 13251
There is no position nor size in a Canvas. Canvas act just as a container for graphics instructions, like Fbo that draw within a Texture, so it have a size.
In Kivy, Canvas.size doesn't exists, but i guess you called your widget a canvas. By default, a Widget size is 100, 100. If you put it into a layout, the size will be changed, when the layout will known its own size. Mean, you need to listen to the changes of the Widget.size, or use a size you known, like Window.size.
Upvotes: 4
Reputation: 10985
I'm gonna guess that you actually need the window size in order to know what your image boundaries are. In this case, you can use:
from kivy.core.window import Window
size = Window.size
And you can of course use the source image of your canvas with PIL or scipy etc. to get its resolution (which the canvas will match).
Upvotes: 3