我无法在下面的代码中进行一些更改。 (1)每个textinput的值(更清楚地,column2的textinput值将不同于column3 textinput值,如我所附的图片)将有所不同,这些值应该全局存储(如'Row'变量是什么做这个代码) (2)标签值应该与图像类似,但在现有代码中,标签获取TextInput(或Row)值。 (3)应该增加(缩放)滚动选项,以便我们可以通过拉动滚动来上/下。 我很感激帮助。感谢。
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty, ListProperty, NumericProperty
from kivy.lang import Builder
from kivy.uix.scrollview import ScrollView
ROWS = ['ac', 'asd', 'kjhgf', 'b', 'bn', 'sdf', 'ytrwd', 'hfs', 'erf', 'boo']
ROWS = ROWS * 10000
Builder.load_string("""
#:import Factory kivy.factory.Factory
#:import dp kivy.metrics.dp
<ScrollSlider>:
ScrollView:
id: scrlvw
bar_width: 0
GridLayout:
id: grid
size_hint_y:None
cols:1
height: self.minimum_height
scroll_y: slider.value
on_touch_move: slider.value = self.scroll_y
Slider:
size_hint_x: None
width: root.width*0.2
id: slider
min: 0
max: 1
orientation: 'vertical'
value: scrlvw.scroll_y
on_value: scrlvw.scroll_y = self.value
<Row>:
spacing: 50
text: txtinpt.text
Label:
text: root.text
TextInput:
id: txtinpt
text: root.text
TextInput:
id: txtinpt
text: root.text
TextInput:
id: txtinpt
text: root.text
Button:
text: 'save'
on_press:
app.data[root.row_id]['text'] = root.text
<Test>:
do_default_tab: False
TabbedPanelItem:
text: 'tab2'
RecycleView:
data: app.data
viewclass: Factory.Row
RecycleBoxLayout:
padding: 50, 50, 50, 50
orientation: 'vertical'
size_hint: 1, None
size: self.minimum_size
default_size_hint: 1, None
default_size: 0, dp(36)
""")
class ScrollSlider(BoxLayout):
def custom_add(self, widget):
self.ids.grid.add_widget(widget)
class Row(BoxLayout):
text = StringProperty()
row_id = NumericProperty()
class Test(TabbedPanel):
pass
class MyApp(App):
data = ListProperty()
scrollslider = ScrollSlider()
def build(self):
self.data = [{'row_id': i, 'text': x} for i, x in enumerate(ROWS)]
test = Test()
return test
if __name__ == '__main__':
MyApp().run()