gpt4 book ai didi

python - Kivy 中的不可编辑文本

转载 作者:行者123 更新时间:2023-11-30 23:25:00 25 4
gpt4 key购买 nike

我正在使用 Kivy 创建注册表。我想要文本框中的文本,该文本在表单加载为不可编辑时出现。从下面可以看出,我可以将“名称”字段编辑为“Na”。我希望输入名称的用户不能执行退格键并删除“名称”。

enter image description here

这是我的代码:

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'
""")

最佳答案

虽然您可能可以做到这一点,但实现起来会很困难。我建议要么将该文本拆分为 Label ,或使用 hint_text (仅当 TextInput 为空且未聚焦时才显示的文本)。

原文:

TextInput:
id: _a
text: 'Name: '

带有标签:

BoxLayout:
Label:
size_hint_x: 0.4 # adjust as necessary, or use None and set width instead
text: 'Name:'
TextInput:
id: _a

使用hint_text:

TextInput:
id: _a
hint_text: 'Name'

关于python - Kivy 中的不可编辑文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23159632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com