python kivy boxlayout设置位置

python kivy boxlayout设置位置,python,linux,kivy,Python,Linux,Kivy,我使用此方法定位BoxLayout layout = BoxLayout(size_hint=(1, None), height=50, spacing=100, pos_hint={'y': 0.5 , 'top': 0.5}) 但是它位于中间,我希望它放置在浮动布局的顶部中心。< /P> 运行时的代码也会给出此警告 [CRITICAL ] [Clock ] Warning, too much iteration done before the next fra

我使用此方法定位BoxLayout

layout = BoxLayout(size_hint=(1, None), height=50, spacing=100, pos_hint={'y': 0.5 , 'top': 0.5})

但是它位于中间,我希望它放置在浮动布局的顶部中心。< /P> 运行时的代码也会给出此警告

[CRITICAL          ] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL          ] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL          ] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL          ] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[CRITICAL          ] [Clock       ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
[INFO              ] [Base        ] Leaving application in progress...
代码如下:

import kivy
from kivy.app import App
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.video import Video
from kivy.uix.relativelayout import RelativeLayout
from kivy.graphics import *
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from random import random
from kivy.properties import ListProperty

kv = '''
<ColoredLabel>:
    size: (100,100)

    background_color:
    canvas.before:
        Color:
            rgba: self.background_color
        Rectangle:
            pos: self.pos
            size: self.size
    '''

Builder.load_string(kv)

class ColoredLabel(Label):
    background_color = ListProperty((0,0,0,1))

class MyApp(App):

    def build(self):
        f = FloatLayout()
        g = GridLayout(cols=5, rows=2, row_force_default=True, row_default_height=80)
        layout = BoxLayout(size_hint=(1, None), height=50, spacing=100, pos_hint={'y': 0.5 , 'top': 0.5})
        v = Video(source='driver.mp4', state='play', options={'eos':'loop'})
        l1 = Label(text="jenkins", font_size=32)
        l2 = Label(text="git", font_size=32)
        f.add_widget(v)

        """
        label1 = ColoredLabel(text="jenkins output", pos_hint={'top': 1, 'right': .1}, size_hint=(None, None) , background_color=(160,160,160,.5))
        f.add_widget(label1)

        label2 = ColoredLabel(text="git output", pos_hint={'top': 1, 'right': .5}, size_hint=(None, None) , background_color=(160,160,160,.5))
        f.add_widget(label2)

        label3 = ColoredLabel(text="dev output", pos_hint={'top': 1, 'right': .8}, size_hint=(None, None) , background_color=(160,160,160,.5))
        f.add_widget(label3)
        """

        text1 = "jenkins"

        label1 = ColoredLabel(text=text1, background_color=(160,160,160,.5))
        layout.add_widget(label1)

        label2 = ColoredLabel(text="git", background_color=(160,160,160,.5))
        layout.add_widget(label2)

        label3 = ColoredLabel(text="portal", background_color=(160,160,160,.5))
        layout.add_widget(label3)

        f.add_widget(layout)


        return f

if __name__ == "__main__":
    MyApp().run()
导入kivy
从kivy.app导入应用程序
从kivy.uix.anchorlayout导入anchorlayout
从kivy.uix.floatlayout导入floatlayout
从kivy.uix.gridlayout导入gridlayout
从kivy.uix.widget导入widget
从kivy.uix.label导入标签
从kivy.uix.video导入视频
从kivy.uix.relativelayout导入relativelayout
从kivy.graphics导入*
从kivy.lang导入生成器
从kivy.uix.boxlayout导入boxlayout
从随机导入随机
从kivy.properties导入ListProperty
kv='''
:
尺寸:(100100)
背景颜色:
在以下情况之前:
颜色:
rgba:self.background\u颜色
矩形:
pos:self.pos
大小:self.size
'''
建筑商荷载(千伏)
类别彩色标签(标签):
背景颜色=列表属性((0,0,0,1))
类别MyApp(应用程序):
def生成(自):
f=浮动布局()
g=网格布局(cols=5,rows=2,row\U force\U default=True,row\U default\U height=80)
layout=BoxLayout(大小提示=(1,无),高度=50,间距=100,位置提示={'y':0.5,'top':0.5})
v=Video(source='driver.mp4',state='play',options={'eos':'loop'})
l1=标签(text=“jenkins”,font\u size=32)
l2=标签(text=“git”,font\u size=32)
f、 添加_小部件(v)
"""
label1=ColoredLabel(text=“jenkins output”,pos_-hint={'top':1,“right':.1},size_-hint=(无,无),background_-color=(160160,.5))
f、 添加_小部件(标签1)
label2=ColoredLabel(text=“git output”,pos_hint={'top':1,“right':.5},size_hint=(无,无),background_color=(160160,.5))
f、 添加_小部件(label2)
label3=ColoredLabel(text=“dev output”,pos_hint={'top':1,“right':.8},size_hint=(无,无),background_color=(160160,.5))
f、 添加_小部件(label3)
"""
text1=“詹金斯”
label1=彩色标签(text=text1,背景颜色=(160160,.5))
布局.添加小部件(label1)
label2=彩色标签(text=“git”,背景颜色=(160160,.5))
布局.添加小部件(label2)
label3=ColoredLabel(text=“portal”,background_color=(160160,.5))
布局.添加小部件(label3)
f、 添加小部件(布局)
返回f
如果名称=“\uuuuu main\uuuuuuuu”:
MyApp().run()

使用
pos\u hint={'top':1}
。不要将
top
y
混在一起,这两个词相互冲突,因为它们都指向正确的位置,这是导致错误的原因

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty

kv = '''
<ColoredLabel>:
    size: (100,100)

    background_color:
    canvas.before:
        Color:
            rgba: self.background_color
        Rectangle:
            pos: self.pos
            size: self.size
    '''

Builder.load_string(kv)

class ColoredLabel(Label):
    background_color = ListProperty((0,0,0,1))

class MyApp(App):
    def build(self):
        f = FloatLayout()
        layout = BoxLayout(size_hint=(1, None), height=50, pos_hint={'top': 1})

        label1 = ColoredLabel(text="jenkins", background_color=(160,160,160,.5))
        layout.add_widget(label1)

        label2 = ColoredLabel(text="git", background_color=(160,160,160,.5))
        layout.add_widget(label2)

        label3 = ColoredLabel(text="portal", background_color=(160,160,160,.5))
        layout.add_widget(label3)

        f.add_widget(layout)


        return f

if __name__ == "__main__":
    MyApp().run()
以及:

layout = BoxLayout(size_hint=(0.5, None), height=50, pos_hint={'top': 1})
layout = BoxLayout(size_hint=(0.5, None), height=50, pos_hint={'top': 1, 'center_x':0.5})