6

I have a piece of code. (1) The TextInput value should be shown , but first it should not be editable, after clicking the corresponding CheckBox, the TextInput will be editable.
(2) Using the iteration, the Label and the TextInput should get the value. The value at Label and TextInput should not be hard coded(although it's there in my code, @FJSevilla helped me for this one).
(3) However, the values of Label and TextInput are stored in a variable in json format. something like this(you can consider like key,value pair in map) [ variable = '{"a" : " Goc" , "b" : "Coc", "c" : "Dow" } '] (you can see diagram for more clearance). I appreciate the help.

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()

kivy userInterface

crazyDelight
  • 89
  • 2
  • 14

1 Answers1

9

First of all, thank you for providing an app which was easy to work with.

I tried to implement what you were looking for except the JSON. I am using a simple list, it should be straightforward to extend my code for a JSON.

Instead of using colums, I am using rows which makes it easier to link together the properties of the label textinput and checkbox.

enter image description here

    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.uix.checkbox import CheckBox
from kivy.lang import Builder

ROWS = ['Goc', 'COC', 'EEE']

Builder.load_string("""

<Test>:
    do_default_tab: False

    TabbedPanelItem:
        text: 'page1'

        Table:
            padding: 50, 50, 50, 50
            orientation: 'vertical'

<Row>:
    spacing: 50
    #orientation: 'vertical'
    size_hint_x: 1
    txt: txtinpt.text
    Label:
        text: root.txt
    TextInput:
        id: txtinpt
        text: root.txt
        disabled: not CheckBox.active
    CheckBox:
        id:CheckBox 
        text: 'CheckBox'
        active: False
    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 Test(TabbedPanel):
    pass

class MyApp(App):

    def build(self):
        test = Test()
        return test


if __name__ == '__main__':
    MyApp().run()
PalimPalim
  • 2,892
  • 1
  • 18
  • 40
  • 2
    Also you can do this in the kv without the function in CheckBox: on_active. Like this: TextInput: disabled: not CheckBox.active – favcau Jul 21 '17 at 14:07
  • @favcau did not know that, thanks. I edited my answer accordingly. – PalimPalim Jul 21 '17 at 14:24
  • dear @PalimPalim thank your for your time. Actually some issues are still there. (1) Label and TextInput both are being edited , but need to edit only TextInput for a corresponding Label. (2) after editing, when I will click a CheckButton again , The corresponding TextInput shoul be again Non_Editable. AND (3) the changes should be shown in the terminal(both the changed Label and TextInput). – crazyDelight Jul 21 '17 at 14:36
  • I don't think I can quite follow you. Please repeat in steps. For the first row: Step1: Label shows a, Textinput disabled shows Goc, Checkbox unchecked. Step2 Checkox is getting unchecked --> TextInput editable. Now should the label change according to TextInput? please give me more detailed steps like that – PalimPalim Jul 21 '17 at 14:47
  • In stepwise: Step1: Label shows "a", Textinput disabled shows "Goc", Checkbox unchecked. Step2: Checkox is getting unchecked --> TextInput editable. Step3: Only the TextInput changed, Label is fixed in it's initial value. Step4: Then showing changes in terminal (both the Label and updated TextInput value ). – crazyDelight Jul 21 '17 at 15:01