Reputation: 939
I am creating a registration form using Kivy. I wants the text in textboxes, which is present when form loads as non-editable. As can be seen from below I can edit "Name" field as "Na". I want that user entering name cannot do a backspace and remove "Name".
This is my code:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
import xml.etree.cElementTree as ET
import fileinput
import sys
import os
Builder.load_string("""
<Reg>:
# This are attributes of the class Reg now
a: _a
b: _b
c: _c
d: _d
e: _e
f: _f
g: _g
result: _result
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
ScreenManager:
size_hint: 1, .9
id: _screen_manager
Screen:
name: 'screen1'
GridLayout:
cols:1
TextInput:
id: _a
text: 'Name: '
TextInput:
id: _b
text: 'Age: '
TextInput:
id: _c
text: 'Phone: '
TextInput:
id: _d
text: 'Email: '
TextInput:
id: _e
text: 'Address: '
TextInput:
id: _f
text: 'Guardian Name: '
TextInput:
id: _g
text: 'Guardian Phone: '
Label:
id: _result
Button:
text: 'Register Me'
# Or you can call a method from the root class (instance of calc)
on_press: root.genxml(*args)
Screen:
name: 'screen2'
Label:
text: 'The second screen'
""")
Upvotes: 1
Views: 676
Reputation: 14794
While you could probably do that, it would be difficult to implement. I would suggest either splitting out that text as a Label
, or using hint_text
(text which only appears if the TextInput
is empty and not focused).
Original:
TextInput:
id: _a
text: 'Name: '
With Label
:
BoxLayout:
Label:
size_hint_x: 0.4 # adjust as necessary, or use None and set width instead
text: 'Name:'
TextInput:
id: _a
With hint_text
:
TextInput:
id: _a
hint_text: 'Name'
Upvotes: 3