1

I am making a GUI. There is a main DataBase(Dictionary) from which its keys are imported from. To import the data easily i have added a TextInput and added a search filter view. Whenever a letter is typed in the Textinput it shows all the keys(in a Label) which match the text's string.

Next to a key (Label text) there is a Button which adds the Label's text to another Label in a new scroll view where different calculations are formed on it.

So i thought before into the next Label i should try to get the value prom the buton by printing it to the consol, and whenever i push the Button next to the Label i only get the last Label's text in the Search View not the Label1s which it is connected to. (But i dont know if i connected it correct, its somehow connected to the naming of the Label's but i don't know how)

Here is an image for understanding my problem better (it shows what i want to do):

image: screen i described

py:

class CalculationView(BoxLayout):
    SearchGridShown = BooleanProperty()
    SLB = ObjectProperty()

    def find_searched_text(self, text):
        Dict = db.databaseDict
        self.ids.SearchGrid.clear_widgets()
        FD = {k: v for (k, v) in Dict.items() if text in k and len(text) > 0}
        for kk, vv in FD.items():

            self.SLB = Label(
                color=(.2, .1, 0, 1),
                text=str(kk))

            self.BTN = Button(
                text='OK',
                background_color=(.05, .3, .05, 1),
                font_size='13sp',
                size_hint=(.1, 1))
            self.BTN.bind(on_press=lambda x: self.add_product_for_calculation(self.SLB.text))
            self.BL = BoxLayout()
            self.BL.add_widget(self.SLB)
            self.BL.add_widget(self.BTN)
            self.ids.SearchGrid.add_widget(self.BL)

    def add_product_for_calculation(self, product):
        print('0' + product + '0')
        Dict = db.databaseDict
        V = Dict[product]
        print(V)

kv:

<CalculationView>:
    orientation: 'vertical'
    size_hint_x: .96
    size_hint_y: .9
    pos_hint: {'x': .02,'y': .0875}

    BoxLayout:
        spacing: 2, 0
        padding: 1
        size_hint: 1, .06
        TextInput:
            size_hint: 1.5, 1
            text: 'Kereses'
            on_focus: self.text = ""
            font_size: '13sp'
            on_text: root.find_searched_text(self.text)
        Button:
            size_hint: .25, 1
            text: 'Keres'
            on_release: root.SearchGridShown = not root.SearchGridShown

    BoxLayout:
        ...

    ScrollView:
        do_scroll_x: False
        do_scroll_y: True
        size_hint_x: 1
        size_hint_y: .9
        pos_hint: {'x': 0,'y': .1}

        GridLayout:
            id: CalculationContainer
            size_hint_y: None
            height: self.minimum_height
            row_force_default: True
            row_default_height: '30dp'
            cols: 4
            spacing: 2, 0
            padding: 1

    BoxLayout:
        ...

    BoxLayout:
        size_hint: 1, .001
        FloatLayout:
            size: self.size
            pos: self.pos
            GridLayout:
                id: SearchGrid
                spacing: 2, 2
                cols:1
                size_hint: .975, None
                height: self.minimum_height
                row_force_default: True
                row_default_height: '35dp'
                pos_hint: {'x': 0 if root.SearchGridShown else 0,'top': 990}
                opacity: .75
                canvas.before:
                    Color:
                        rgba: 1, 1, 1, 1
                    Rectangle:
                        size: self.size
                        pos: self.pos
Mate
  • 301
  • 1
  • 10
  • 1
    1) change `self.SLB` to `SLB` 2) change `self.BTN` to `BTN` 3) change `self.BTN.bind(on_press=lambda x: self.add_product_for_calculation(self.SLB.text))` to `BTN.bind(on_press=lambda *args, t=SBL.text: self.add_product_for_calculation(t))` – eyllanesc Jul 28 '19 at 18:17
  • Great comment @eyllanesc! Forgive my very beginner question, and thank you for your answer! – Mate Jul 28 '19 at 20:29

0 Answers0