简体   繁体   中英

How can I put a button to be always in the center and bottom of my App?

I'd like to put an 'Update Button' in the center and bottom of my app, but I also need to add some widgets in the screen. I put a BoxLayout to be always in the center and bottom of my app, but I need to put a Button inside it and it has to be always in the BoxLayout center bottom too. What I did:

My .kv source code:

<WindowMain>:
orientation: 'horizontal'

BoxLayout:
    orientation: 'vertical'
    size_hint: .1, .1
    pos_hint: {"x":1., "bottom":1.}
    padding: 2

    Button:
        size_hint: .2, 1.
        pos_hint: {'x': .5, 'y': 1.}            
        font_name: 'consola'
        text: 'Update'

您可以在按钮的左侧和右侧添加两个空标签,并使用size_hint属性将其size_hint

You can use the 'FloatLayout' for positioning of the widgets in contrast to the main window.

in py:

from kivy.uix.floatlayout import FloatLayout

class MainWindow(FloatLayout):
    pass

in kv:

<WindowMain>:
    Button:
        size_hint: .2, .1
        pos_hint: {'x': .4, 'y': 0}            
        font_name: 'consola'
        text: 'Update'

This should have the button start at 40% in and end at 60% being 10% high up. You can then add other widgets anywhere you like in the FloatLayout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM