简体   繁体   English

如何放置一个始终位于应用程序中央和底部的按钮?

[英]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. 我将BoxLayout始终放置在应用程序的中央和底部,但是我需要在其中放置一个Button,并且它也必须始终位于BoxLayout中央的底部。 What I did: 我做了什么:

My .kv source code: 我的.kv源代码:

<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. 您可以使用“ FloatLayout”相对于主窗口定位小部件。

in py: 在py中:

from kivy.uix.floatlayout import FloatLayout

class MainWindow(FloatLayout):
    pass

in kv: 在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. 这应该使按钮开始于40%,结束于60%,即高10%。 You can then add other widgets anywhere you like in the FloatLayout. 然后,您可以在FloatLayout中的任意位置添加其他小部件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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