Can't set BoxLayout size

2,386 views
Skip to first unread message

Kensei.akita

unread,
Sep 3, 2012, 11:25:10 AM9/3/12
to kivy-...@googlegroups.com

First of all, if they are some system diffrences, I work on Ubuintu 12.04, using actual Kivy version. My problem is unability to set layout size.

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
class TestApp(App):
def build(self):
    layout
= BoxLayout(orientation='vertical', size=(200,200))
    btn1
= Button(text='Hello', size=(50,50), size_hint=(None, None))
    btn2
= Button(text='World', size=(50,50), size_hint=(None, None))
    layout
.add_widget(btn1)
    layout
.add_widget(btn2)
   
return layout
TestApp().run()

Have You got any idea?

Mathieu Virbel

unread,
Sep 3, 2012, 12:06:12 PM9/3/12
to kivy-...@googlegroups.com
You must desactivate the size_hint:
> layout= BoxLayout(orientation='vertical', size=(200,200),
size_hint=(None, None))

Ref:
http://kivy.org/docs/api-kivy.uix.layout.html#understanding-size-hint-property-in-widget

Mathieu


Le 03/09/2012 17:25, Kensei.akita a �crit :
> First of all, if they are some system diffrences, I work on Ubuintu
> 12.04, using actual Kivy version. My problem is unability to set layout
> size.
>
> |from kivy.appimport App
> from kivy.uix.buttonimport Button
> from kivy.uix.boxlayoutimport BoxLayout
> class TestApp(App):
> def build(self):
> layout= BoxLayout(orientation='vertical', size=(200,200))
> btn1= Button(text='Hello', size=(50,50), size_hint=(None, None))
> btn2= Button(text='World', size=(50,50), size_hint=(None, None))
> layout.add_widget(btn1)
> layout.add_widget(btn2)
> return layout
> TestApp().run()
> |
>
> Have You got any idea?
>
> --
>
>
>

Kensei.akita

unread,
Sep 3, 2012, 12:12:15 PM9/3/12
to kivy-...@googlegroups.com
I wrote something like that, and it didn't help. Did I understand , what You mean? 
def build(self):
layout = BoxLayout(orientation='vertical')
layout.size_hint = (None, None)
layout.width = 250
layout.height = 250

Kensei.akita

unread,
Sep 3, 2012, 12:23:09 PM9/3/12
to kivy-...@googlegroups.com
Pardon, layout=  BoxLayout(orientation='vertical',  size=(200,200), size_hint=(None, None)) also doesn't work

Mathieu Virbel

unread,
Sep 3, 2012, 12:30:09 PM9/3/12
to kivy-...@googlegroups.com
Yes it's working :)
But you also set a size to the button... why ?

You must decide if you want your boxlayout to set the size of the
children or not. Just remove all the size/size_hint from the button.
And, reread the documentation, and check the example. This is a standard
case used a lot everywhere :)

Mathieu

Le 03/09/2012 18:23, Kensei.akita a �crit :
> Pardon, layout= BoxLayout(orientation='vertical',
> size=(200,200), size_hint=(None, None)) also doesn't work
>
> --
>
>
>

Reply all
Reply to author
Forward
0 new messages