0
我有一段代碼。 (1)應該顯示TextInput值,但首先它不應該是可編輯的,點擊相應的CheckBox後,TextInput將是可編輯的。
(2)使用迭代,Label和TextInput應該得到該值。 Label和TextInput的值不應該被硬編碼(儘管它在我的代碼中,@FJSevilla幫助我完成這個)。
(3)但是,Label和TextInput的值以json格式存儲在變量中。 (你可以考慮像地圖中的鍵,值對)[變量='{「a」:「Goc」,「b」:「Coc」,「c」:「Dow」}'] (你可以請參閱圖表以獲得更多通關)。 我很感激幫助。如何在Python中使用kivy在TextInput中啓用/禁用編輯
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.lang import Builder
Builder.load_string("""
<Test>:
do_default_tab: False
TabbedPanelItem:
text: 'page1'
BoxLayout:
padding: 50, 50, 50, 50
orientation: 'horizontal'
BoxLayout:
spacing: 50
orientation: 'vertical'
size_hint_x: 1
Label:
text: 'a'
Label:
text: 'b'
Label:
text: 'c'
BoxLayout:
spacing: 50
orientation: 'vertical'
TextInput:
text: 'Goc'
TextInput:
text: 'Coc'
TextInput:
text: 'Dow'
BoxLayout:
spacing: 50
orientation: 'vertical'
size_hint_x: 0.40
CheckBox:
text: 'CheckBox'
CheckBox:
text: 'CheckBox'
CheckBox:
text: 'CheckBox'
BoxLayout:
spacing: 50
orientation: 'vertical'
size_hint_x: 0.60
Button:
text: 'save'
Button:
text: 'save'
Button:
text: 'save'
""")
class Test(TabbedPanel):
pass
class MyApp(App):
def build(self):
test = Test()
return test
if __name__ == '__main__':
MyApp().run()
所有的
您也可以在KV做到這一點沒有在複選框功能:on_active。像這樣:TextInput:disabled:not CheckBox.active – favcau
@favcau不知道,謝謝。我相應地編輯了我的答案。 – PalimPalim
親愛的@PalimPalim感謝您的時間。其實有些問題仍然存在。 (1)標籤和TextInput都正在編輯,但只需要編輯相應標籤的TextInput。 (2)編輯完成後,當我再次點擊一個CheckButton時,對應的TextInput將再次爲Non_Editable。和(3)應該在終端中顯示更改(包括更改的標籤和TextInput)。 – crazyDelight