Add/remove rows on button press

10 views
Skip to first unread message

Joseph Edwards

unread,
Dec 1, 2018, 5:23:17 AM12/1/18
to Kivy users support

I am working on a gui that will replace an excel spreadsheet as part of a short workflow to a database. I am aiming to keep a similar format to the spreadsheet with rows of 3 columns:

Number ID

Category (spinner menu)

Text Input

 

The overall layout of the gui is exactly how I'd like it and I've achieved one row, now I need to work out the functionality of adding duplicate rows.

 

I want to use the buttons in the bottom left to add and subtract the rows, components of each new row will also need a unique ID so I can use the user input data individually.

 

I am hoping I haven't been too ambitious with this project as I love the slick look of Kivy and the end result doesn't seem too far away now, but unfortunately I have reached a point that requires a higher skill level than I currently have.

I am working through the Dusty Phillips Kivy book but would love some expert guidance in the meantime to help maintain momentum on the project.

 

I hope this makes sense and thanks for reading.

 

---------------------------------- GIU.PY -------------------------------------

import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.properties import ObjectProperty
kivy.require('1.10.1')

class GUILayout(BoxLayout, GridLayout):

    text_input = ObjectProperty()

    def retrieve_text(self):
        print(self.text_input.text)


class GUIApp(App):

    def build(self):
        return GUILayout()


GUIApp = GUIApp()
GUIApp.run()

  ---------------------------------- GIU.KV -------------------------------------  

#: import main GUI


GUILayout:

<GUILayout>:
    orientation: "vertical"
    text_input: input_box
    padding: 10
    spacing: 10

    BoxLayout:
        orientation: "horizontal"
        height: 60


        BoxLayout:
            orientation: "horizontal"
            size_hint_x: .25

            TabbedPanel:
                do_default_tab: False


                # ----------- TAB 1 ------------

                TabbedPanelItem:
                    text: "tab1"
                    BoxLayout:
                        orientation: "horizontal"
                        size_hint_y: .08

                        padding: 10
                        spacing: 10

                        ##### The below 3 objects is the 'row' that I want to be able to add and remove
                        Label:
                            text: '1'
                            font_size: 40
                            size_hint_x: .04

                        Spinner:
                            id: categories
                            text: 'Select Category'
                            values: ['One', 'Two', 'Three']
                            size_hint_x: .3

                        TextInput:
                            id: input_box
                            font_size: 40
                            size_hint_x: .8


                # ----------- TAB 2 ------------

                TabbedPanelItem:
                    text: "tab2"


                # ----------- TAB 3 ------------

                TabbedPanelItem:
                    text: "tab3"


                # ----------- TAB 4 ------------

                TabbedPanelItem:
                    text: "tab4"


                # ----------- TAB 5 ------------

                TabbedPanelItem:
                    text: "tab5"


    # --------- Bottom row buttons ----------

    GridLayout:
        rows: 1
        cols: 6
        padding: 1
        spacing: 5
        size_hint_y: .05

        # --------- MINUS ---------
        Button:
            text: " - "
            font_size: 70
            size_hint_x: .1

        # -------- SUBTRACT -------
        Button:
            text: " + "
            font_size: 50
            size_hint_x: .1


        # ----- UPDATE MAESTRO -----
        Button:
            text: "Update Maestro"
            size_hint_x: .4
            on_press: root.retrieve_text()


        # -------- SETTINGS --------
        Button:
            text: "Settings"
            font_size: 30
            size_hint_x: .2

Elliot Garbus

unread,
Dec 1, 2018, 1:13:34 PM12/1/18
to Kivy users support
I can think of 2 approaches to take:

1) If you are confident you set a max number of rows, create them in Kv, and used the widget disable and opacity attributes to turn them on and off.
2) If the number of rows is going to be really dynamic, create or remove them in python with add_widget() and remove_widget()
Reply all
Reply to author
Forward
0 new messages