猕猴桃标签的位置 [英] Position of The Kivy Label

查看:111
本文介绍了猕猴桃标签的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相同的实验,我尝试使用以下代码定位标签:

In the same experiment, I tried to positionize a Label using this code:

class TetraApp(App):

    def build(self):
        Window.size=(875,600)
        Window.clearcolor = (1, 1, 1, 1)
        b = BoxLayout(orientation ='vertical')

#Here, the pos and pos hint doesnt seem to work for small values

        self.lab=Label(text="How Can I Help\n          You?", font_size='35',color =[0, 0, 0, 1],font_name='VarelaRound-Regular',pos=[0.1,0.01],pos_hint={'x': 0.005, 'y': 0})

        self.t = TextInput(hint_text='Say Something...', size_hint=(1,0.25), multiline=False)
        self.t.bind(on_text_validate=self.enterClicked)
        b.add_widget(TitleBar())
        b.add_widget(self.lab)
        b.add_widget(self.t)
        Window.borderless=True
        return b

这就是我得到的:

This is what i get:

推荐答案

问题不是定位(BoxLyout处理该问题),而是您的Labelsize.您需要为Label提供一个height.像这样:

The problem is not positioning (the BoxLyout handles that), but the size of your Label. You need to provide a height for the Label. Something like:

self.lab=Label(text="How Can I Help\n          You?", font_size='35',color =[0, 0, 0, 1], font_name='VarelaRound-Regular', size_hint_y=None, height=100)

您的TitleBar具有固定的高度,TextInput设置为占BoxLayout高度的四分之一,并且由于默认的size_hint_y为1.0,因此您的Label占据了其余空间.将Label设置为固定高度,将其余空间留给TextInput.您可以使用size_hint_y而不是固定高度,这将允许LabelTextInput共享与其size_hint_y值成比例的空间.

Your TitleBar has a fixed height, the TextInput is set to take up a quarter of the BoxLayout height, and since the default size_hint_y is 1.0, your Label takes the rest of the space. Giving the Label a fixed height, leaves the rest of the space to the TextInput. You could use size_hint_y instead of the fixed height, and that would allow the Label and the TextInput to share the space proportional to their size_hint_y values.

这篇关于猕猴桃标签的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆