猕猴桃标签的位置 [英] Position of The Kivy Label
问题描述
在相同的实验,我尝试使用以下代码定位标签:
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
处理该问题),而是您的Label
的size
.您需要为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
而不是固定高度,这将允许Label
和TextInput
共享与其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屋!