我想在基維啓用/禁用Textinput。多個TextInput在那裏。 (1)當我點擊一個TextInput時,那個特定的TextInput將是可編輯的。 (2)默認情況下,所有內容都將設置爲禁用模式。 (3)滾動條應該在那裏,假設有數百個輸入在那裏(我無法提供)。 (4)我面臨的另一個問題是:當有數百個輸入時,TextInput的文本不能正確顯示。那麼是否有任何選項可以設置默認大小,以便它不會影響是否只有2-3個輸入或100個輸入。 (5)TextInput和label處的值應該是動態的,應該存儲在全局變量中。 @PalimPalim已經幫助我瞭解現有的代碼。謝謝大家。如何啓用/禁用多個TextInput在聚焦在基尼在python
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()
清晰地解釋,謝謝@Tshirtman! – crazyDelight
刪除標籤的更新很簡單,只需刪除「text:txtinpt。文本「行規則,它只會在你現在保存該值時更新,對於其他的事情,向你的Row類添加屬性,並在字典中使用相同的名稱傳遞它們,它會自動工作。 –
Tshirtman
when我在行規則中添加了更多的TextInput,它顯示「聲明後無效的數據」,並且在字典中傳遞屬性時,它在枚舉過程中顯示:「ValueError:需要超過2個值才能解包」。 – crazyDelight