【发布时间】:2017-12-31 06:02:30
【问题描述】:
我正在尝试在 kivy 中启用/禁用 Textinput。有多个 TextInput。 (1) 当我点击一个 TextInput 时,那个特定的 TextInput 将是可编辑的。 (2) 默认情况下,所有内容都将设置为禁用模式。 (3)滚动条应该在那里,因为假设那里有数百个输入。(我无法带来)。 (4) 我面临的另一个问题是:当有数百个输入时,TextInput 的文本无法正确显示。那么是否有任何选项可以设置默认大小,以便它不会影响只有 2-3 个输入或 100 个输入。 (5) TextInput 和 label 的值应该是动态的,应该全局存储在变量中。 @PalimPalim 已经为我提供了现有代码的帮助。谢谢大家。
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.uix.textinput import TextInput
from kivy.lang import Builder
kivy.uix.scrollview import ScrollView
from kivy.properties import StringProperty
ROWS = ['ac', 'asd', 'kjhgf', 'b' ,'bn', 'sdf', 'ytrwd', 'hfs' ,'erf', ...]
Builder.load_string("""
<Test>:
do_default_tab: False
TabbedPanelItem:
text: 'page1'
scrollView:
size_hint: (None, None)
size: (400, 400)
Table:
padding: 50, 50, 50, 50
orientation: 'vertical'
<Row>:
spacing: 50
size_hint: 1, .9
txt: txtinpt.text
Label:
text: root.txt
TextInput:
id: txtinpt
text: root.txt
Button:
text: 'save'
""")
class Table(BoxLayout):
def __init__(self, **kwargs):
super(Table, self).__init__(**kwargs)
for row in ROWS:
self.add_widget(Row(row))
class Row(BoxLayout):
txt = StringProperty()
def __init__(self, row, **kwargs):
super(Row, self).__init__(**kwargs)
self.txt = row
class ScrollableLabel(ScrollView):
text = StringProperty('')
class Test(TabbedPanel):
pass
class MyApp(App):
def build(self):
test = Test()
return test
if __name__ == '__main__':
MyApp().run()
【问题讨论】:
标签: python user-interface kivy edit textinput