Search code examples
pythonkivytextinputkivy-language

Field content not always visible in kivy Textinput


I am encountering some strange/unexpected behaviour when displaying content in a Textinput field (Initially used for new record input - subsequently for show record data). Data is available in a dictionary and is assigned to Textinput fields. For short data the characters will be hidden sometimes:

enter image description here

It seems that the cursor is at the end of the string and all characters are at the left side and 'hidden'(?) behind the label. After mouseclick in the field and arrow left, the characters appear.

enter image description here

What is wrong in my kv definitions? :

BoxLayout:
    orientation: "horizontal"
    height: 25
    size_hint_y: None
    Label:
        id: _socialsource_label
        size_hint: 0.35,1
        text: "Social access token:"
        size: self.texture_size
        halign: 'left'
        valign: 'middle'
        font_size: 14
        color: .3,.3,.3,1

    TextInput:
        id: socialsource
        padding: 4,2,4,0
        size_hint: 0.65,1
        font_size: 14
        multiline: False
        readonly: False
        text_size: self.width, None
        halign: 'left'
        foreground_color: .3,.3,.3,1
        disabled_foreground_color: .3,.3,.3,1
        background_normal: './images/tinputBGnormal.png'
        background_active: './images/tinputBGactive.png'
        background_disabled_normal: './images/tinputBGdisnormal.png'
        background_disabled_active: './images/tinputBGdisactive.png'

In the python code the data is assigned by:

self.socialchnl.text = projdict[0]['PRJSocchnl:']
self.socialsource.text = projdict[0]['PRJSocsrc:']
self.socialprovdr.text = projdict[0]['PRJSocprv:']

Solution

  • After gaining more experience with kivy, I came up with the following solution: Just set the cursor position at the same time you assign new data to the textinput:

    self.socialsource.text = projdict[0]['PRJSocsrc:']
    self.socialsource.cursor = (0, 0)