Forum Archive

TextField Pythonista-anchors

DavinE

@mikael
it seems that size_to_fit takes no effect on a TextField.. ?
is it an Bug ?
the height don't changes

Sample Code:

createCustomersCustomersProjectTextField = getTextField_area(
    ui.TextField(name="createCustomersCustomersProjectTextField"),
    "createCustomersCustomersProjectTextField",
    self.DEVICE,
)
createCustomersCustomersProjectTextField.size_to_fit()
createCustomersCustomersProjectTextField.width = self.WIDTH - 75
attach(createCustomersCustomersProjectTextField).below(
    createCustomersCustomersProjectLabel
)
mikael

@DavinE, TextField is by definition a one-line text field. The height will probably change with font size, but not by the amount of text.

You might have been thinking of a TextView, see the sample below. (And remember to set the desired width before automatic sizing.)

import ui


v = ui.View()

tv = ui.TextView(
    text='Try this out\nfor size',
    font=('Arial Rounded MT Bold', 32),
    flex='RLTB',
)
tv.width = 200
tv.size_to_fit()
tv.center = v.bounds.center()

v.add_subview(tv)

v.present('fullscreen')
DavinE

@mikael said:

@DavinE, TextField is by definition a one-line text field. The height will probably change with font size, but not by the amount of text.

My Font size is 16...
I use My Textfield in combination with an Action..
Then i will use the height Option for the TextField this will work

I tried TextViews but this dont worked..

Thanks @mikael for your Great help

JonB

For TextView, you have to define a delegate in order to use actions.

DavinE

Thanks @JonB