0

I'm trying to build a app in Kivy framework and need to pass data between widget's, for example, take the values from all the input's and when click on the button "Start" print in the console all the values from the input's.

main.py

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout  
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.label import Label
from kivy.graphics import Color
from kivy.properties import VariableListProperty, OptionProperty,ObjectProperty
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button

class Banner(Widget):
    def __init__(self, **kwargs):
        super(Banner, self).__init__(**kwargs)

class TestName(Widget):
    def __init__(self, **kwargs):
        super(TestName, self).__init__(**kwargs)

class TimeSampling(Widget):
    def __init__(self, **kwargs):
        super(TimeSampling, self).__init__(**kwargs)

class ImageName(Widget):
    def __init__(self, **kwargs):
        super(ImageName, self).__init__(**kwargs)

class StartButton(Widget):
    def __init__(self, **kwargs):
        super(StartButton, self).__init__(**kwargs)

class ContainerBox(BoxLayout):
    def __init__(self, **kwargs):
        super(ContainerBox, self).__init__(**kwargs)

class EyeData(App):
    title = 'EyeData Desktop App'

    def build(self):
        return ContainerBox()

if __name__ == '__main__':
    EyeData().run()

eyedata.kv

<Banner>:
    BoxLayout:
        canvas.before:
            Color:
                rgba: 0, 0.6, 0.7, 0.9
            Rectangle:
                pos: self.pos
                size: self.size
        size: root.size
        pos:root.pos
        orientation: 'horizontal'
        Label:
            text: '[b]EyeData[/b]'
            markup: True
            font_size: 30
            text_size: self.size
            valign: 'bottom'
            line_height: 2
            padding_x: 40
        Label:
            text: '[i]A smart solution for markting[/i]'
            markup: True
            font_size: 20
            text_size: self.size
            halign: 'right'
            valign: 'bottom'
            line_height: 3
            padding_x: 40

<TestName>:
    BoxLayout:
        canvas.before:
            Color:
                rgba: 1, 1, 1, 0.2
        Rectangle:
            pos: self.pos
            size: self.size
        size: root.size
        pos: root.pos
        orientation:'horizontal'

        Label:
            text: '[b]Test Name:[/b]'
            markup: True
            font_size:15
            text_size: self.size
            valign: 'middle'
            size_hint_x: 0.2
            padding_x: 40

        AnchorLayout:
            size_hint_x: 0.8
            anchor_y: 'center'
            anchor_x: 'left'
            padding: (0,0,40,0)

        TextInput:
            font_size: 18
            size_hint_y: None
            height: 30
            text: ""
            multiline: False


<TimeSampling>:
    BoxLayout:
        canvas.before:
            Color:
                rgba: 1, 1, 1, 0.2
            Rectangle:
                pos: self.pos
                size: self.size
        size: root.size
        pos: root.pos
        orientation:'horizontal'

        Label:
            text: '[b]Time of Sampling(sec):[/b]'
            markup: True
            font_size:15
            text_size: self.size
            valign: 'middle'
            size_hint_x: 0.3
            padding_x: 40

        AnchorLayout:
            anchor_y: 'center'
            anchor_x: 'left'
            padding: (0,0,40,0)

            TextInput:
                font_size: 18
                size_hint_y: None
                height: 30

<ImageName>:
    BoxLayout:
        canvas.before:
            Color:
                rgba: 1, 1, 1, 0.2
            Rectangle:
                pos: self.pos
                size: self.size
        size: root.size
        pos: root.pos
        orientation:'horizontal'

        Label:
            text: '[b]Image:[/b]'
            markup: True
            font_size:15
            text_size: self.size
            valign: 'middle'
            size_hint_x: 0.3
            padding_x: 40

        AnchorLayout:
            size_hint_x: 0.2
            anchor_y: 'center'
            anchor_x: 'center'

            Button:
                text: 'Select:'
                size_hint_y: None
                height: 30

        AnchorLayout:
            anchor_y: 'center'
            anchor_x: 'left'
            padding: (0,0,40,0)

            TextInput:
                font_size: 18
                size_hint_y: None
                height: 30

<StartButton>:
    BoxLayout:
        canvas.before:
            Color:
                rgba: 1, 1, 1, 0.2
            Rectangle:
                pos: self.pos
                size: self.size
        size: root.size
        pos: root.pos
        orientation:'horizontal'

        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'center'

            Button:
                size_hint_y: None
                size_hint_x: None
                height: 40
                width: 400
                text: 'Start'
                background_color: 0, 0.5, 1, 1

<ContainerBox>:
    spacing:1
    orientation:'vertical'
    Banner: 
    TestName:
    TimeSampling:
    ImageName:
    StartButton:

if you have a suggestion's about the code, you are welcome!

Jorge Almonacid
  • 583
  • 2
  • 5
  • 9
  • read Kivy doc: [Button](https://kivy.org/docs/api-kivy.uix.behaviors.button.html) to see how to assign function to button. – furas Oct 05 '16 at 01:54
  • or kv doc: https://kivy.org/docs/guide/lang.html and `Button: on_press: function_name()` – furas Oct 05 '16 at 01:57
  • You don't need to overwrite the `__init__` function in that way, you can simply do `class A(D): pass`. Also if you don't want to do anything on the python side with the classes you could also use [dynamic classes in kv](https://kivy.org/docs/guide/lang.html#dynamic-classes). – syntonym Oct 05 '16 at 07:13
  • There's an explanation of such thing (I put it here as a duplicate), but the question isn't labeled very hm... explanatory. But then again, the question is directly about the checkboxes, though it basically targets Python's class communication. I think I tried to edit the name before, but it wasn't succesful. – Peter Badida Oct 05 '16 at 19:34

0 Answers0