【发布时间】:2020-08-19 23:23:30
【问题描述】:
我想收到的东西似乎很简单;我想更改我的Label 和TextInput 小部件的大小和位置,同时动态调整大小。由于这些参数由布局控制,我正在尝试将我的TextInput 链接到FloatLayout 和我的Label 到AnchorLayout,但这并没有太大帮助。我做错了什么?
理想的结果:
- 来自
Label的文本集中在该层的底部 - TextInput 包含它当前填充的图层的 20% 的高度和 80% 的宽度
import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.core.window import Window
from kivy.utils import get_color_from_hex
class SearchPerformer(GridLayout):
pass
class MyApp(App):
def build(self):
return SearchPerformer()
if __name__ == '__main__':
Window.clearcolor = get_color_from_hex('#F9E29C')
MyApp().run()
还有我定义 UI 的 KV 文件:
<SearchPerformer>
GridLayout:
size: root.size
cols: 2
rows: 2
BoxLayout:
orientation: 'vertical'
rows: 2
cols: 1
AnchorLayout:
Label:
text: "MAKE"
font_size: 60
anchor_x: "center"
anchor_y: "bottom" # Although specifying bottom, my text label doesn't move to the bottom of the layer
FloatLayout: # When FloatLayout is added, TextInput automatically disappears
TextInput:
border: (50, 50, 50, 50)
multiline: False
font_size: 30
size_hint: .8, .2 # So then 80% width and 50% in height of this layer does not work as well...
BoxLayout:
orientation: 'vertical'
rows: 2
cols: 1
Label:
text: "MODEL"
font_size: 60
TextInput:
border: (50, 50, 50, 50)
multiline: False
font_size: 30
BoxLayout:
orientation: 'vertical'
rows: 2
cols: 1
Label:
text: "YEAR"
font_size: 60
TextInput:
border: (50, 50, 50, 50)
multiline: False
font_size: 30
BoxLayout:
orientation: 'vertical'
rows: 2
cols: 1
Label:
text: "ENGINE"
font_size: 60
TextInput:
border: (50, 50, 50, 50)
multiline: False
font_size: 30
【问题讨论】:
标签: python kivy kivy-language