Python Kivy-如何降低TextInput的高度 [英] Python kivy - how to reduce height of TextInput
问题描述
我正在使用kivy为应用程序制作非常简单的GUI.没什么复杂的,非常简单的布局.
I am using kivy to make a very simple gui for an application. Nothing complex, very simple layout.
尽管如此,我在使用TextInputs时还是遇到了困难……它们始终以全高显示,我无法设法使它们调整为像高度一样的合理的"文本高度.
Nevertheless I am having a hard time with TextInputs...They always display with full height and I can't manage to make them adjust to a "reasonable" text-height like height.
我使用kv文件样式是因为我发现它更干净,更轻松地将其集成到已存在的应用程序中...我希望尽可能减少该应用程序的gui-python代码.
I am using the kv files style since I find it cleaner and easier to integrate it in an already existing app...I would like to reduce as much as possible the gui-python code of the app.
这是我为TextInput所获得的(无助于添加gui的其他部分).
Here is what I got for the TextInput (useless to add other parts of the gui).
Python代码
# textInput.py
from kivy import require
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang.builder import Builder
Builder.load_file('path/to/kv/file/textInput.kv')
require('1.10.0')
class MainScreen(BoxLayout):
pass
class Test(App):
def build(self):
self.title = 'Testing textInput'
return MainScreen()
if __name__ == '__main__':
Test().run()
KV代码
# textInput.kv
<MainScreen>
orientation: 'vertical'
# Third section title
Label:
size_hint: (1, .1)
text: 'Setup Connection'
font_size: 25
# Third section Box
BoxLayout:
size_hint: (1, .2)
padding: [100, 0, 100, 0]
BoxLayout:
Label:
size_hint: (.2, 1)
text: 'Host'
TextInput:
height: self.minimum_height
multiline: False
text: 'localhost'
Label:
size_hint: (.2, 1)
text: ''
Label:
size_hint: (.2, 1)
text: 'Port'
TextInput:
size_hint: (.2, 1)
multiline: False
text: '502'
我尝试了很多东西,在这里的代码中,我试图同时使用size_hint和height ...,但是没有用..
I have tried lot of stuff, in the code here I am trying both to use size_hint and height...but none works..
推荐答案
要设置小部件的高度,请首先将size_hint_y
设置为None
,然后可以将height
设置为所需的任何值. /p>
To set a height of a widget, first set the size_hint_y
to None
and then you can set the height
to whatever you want.
TextInput:
size_hint: (.2, None)
height: 30
multiline: False
text: '502'
这篇关于Python Kivy-如何降低TextInput的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!