Python kivy - how to reduce height of TextInput

2024/10/2 16:15:15

I am using kivy to make a very simple gui for an application. Nothing complex, very simple layout.

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.

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.

Here is what I got for the TextInput (useless to add other parts of the gui).

Python code

# textInput.py
from kivy import require
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang.builder import BuilderBuilder.load_file('path/to/kv/file/textInput.kv')require('1.10.0')class MainScreen(BoxLayout):passclass Test(App):def build(self):self.title = 'Testing textInput'return MainScreen()if __name__ == '__main__':Test().run()

KV code

# textInput.kv
<MainScreen>orientation: 'vertical'# Third section titleLabel:size_hint: (1, .1)text: 'Setup Connection'font_size: 25# Third section BoxBoxLayout:size_hint: (1, .2)padding: [100, 0, 100, 0]BoxLayout:Label:size_hint: (.2, 1)text: 'Host'TextInput:height: self.minimum_heightmultiline: Falsetext: 'localhost'Label:size_hint: (.2, 1)text: ''Label:size_hint: (.2, 1)text: 'Port'TextInput:size_hint: (.2, 1)multiline: Falsetext: '502'

I have tried lot of stuff, in the code here I am trying both to use size_hint and height...but none works..

Answer

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: 30multiline: Falsetext: '502'
https://en.xdnf.cn/q/70827.html

Related Q&A

Python-Matplotlib boxplot. How to show percentiles 0,10,25,50,75,90 and 100?

I would like to plot an EPSgram (see below) using Python and Matplotlib. The boxplot function only plots quartiles (0, 25, 50, 75, 100). So, how can I add two more boxes?

Python Pandas reads_csv skip first x and last y rows

I think I may be missing something obvious here, but I am new to python and pandas. I am reading a large text file and only want to use rows in range(61,75496). I can skip the first 60 rows withkeyword…

Combine two arrays data using inner join

Ive two data sets in array: arr1 = [[2011-10-10, 1, 1],[2007-08-09, 5, 3],... ]arr2 = [[2011-10-10, 3, 4],[2007-09-05, 1, 1],... ]I want to combine them into one array like this: arr3 = [[2011-10-10, 1…

How to change fontsize of individual legend entries in pyplot?

What Im trying to do is control the fontsize of individual entries in a legend in pyplot. That is, I want the first entry to be one size, and the second entry to be another. This was my attempt at a so…

Split array into equal sized windows [duplicate]

This question already has answers here:Sliding window of M-by-N shape numpy.ndarray(8 answers)Closed 10 months ago.I am trying to split an numpy.array of length 40 into smaller, equal-sized numpy.array…

Is there a way to send a click event to a window in the background in python?

So Im trying to build a bot to automate some actions in a mobile game that Im running on my pc through Bluestacks.My program takes a screenshot of the window, looks for certain button templates in the …

how to store an image into redis using python / PIL

Im using python and the Image module(PIL) to process images.I want to store the raw bits stream of the image object to redis so that others can directly read the images from redis using nginx & htt…

Delete OCR word from Image (OpenCV,Python)

So, from what I can begin..I am working with OCR. The script works pretty well for what I need. It detects the words with an accuracy which for me is ok.This is the result: 100% accuracy with attached …

pandas.to_datetime inconsistent time string format

I am attempting to convert the index of a pandas.DataFrame from string format to a datetime index, using pandas.to_datetime().Import pandas:In [1]: import pandas as pdIn [2]: pd.__version__ Out[2]: 0.1…

Python NLTK WUP Similarity Score not unity for exact same word

Simple code like follows gives out similarity score of 0.75 for both cases. As you can see both the words are the exact same. To avoid any confusion I also compared a word with itself. The score refuse…