Python KIVY: recursive DropDown - python

I would like to create a DropDown that contains 3 other DropDowns that contains 3 buttons each.
I would like the first DropDown to open three more DropDowns, when we click on one of them, three buttons appear, and in any case when a button appears, which is below down without display bug. When you click on a dropdown for se second time, it hides its children widgets.
I'm using this way to create a dropdown:
.py:
from kivy.app import App
from kivy.uix.dropdown import DropDown
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.properties import StringProperty
class MyScreenManager(ScreenManager):
button_text = StringProperty('Show possibilities')
def __init__(self, **kwargs):
super(MyScreenManager, self).__init__(**kwargs)
self.dropdown = CustomDropDown(self)
def open_drop_down(self, widget):
self.dropdown.open(widget)
class MyScreen(Screen):
def __init__(self, **kwargs):
super(MyScreen, self).__init__(**kwargs)
class CustomDropDown(DropDown):
def __init__(self, screen_manager, **kwargs):
super(CustomDropDown, self).__init__(**kwargs)
self.sm = screen_manager
def on_select(self, data):
self.sm.button_text = data
Builder.load_file("debug.kv")
class MyAppli(App):
def build(self):
return MyScreenManager()
if __name__ == '__main__':
MyAppli().run()
.kv:
<MyScreenManager>:
MyScreen:
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
Button:
text: root.button_text
size:(200,50)
size_hint:(None,None)
on_release: root.open_drop_down(self)
<CustomDropDown>:
Button:
text:"Item 1"
size:(200,50)
size_hint:(None,None)
on_release: root.select("ONE")
Button:
text:"Item 2"
size:(200,50)
size_hint:(None,None)
on_release: root.select(self.text)
Button:
text:"Item 3"
size:(200,50)
size_hint:(None,None)
on_release: root.select("THREE")

Adding another custom drop down class and adding a button method to open/dismiss the second drop down. The open_drop2() method does the open/dismiss. Added padding to each Button in an attempt to show the cascading a bit. Additional cascading can be done using the same scheme, i.e., add a CustomDropDown3 class that is opened by a button in CustomDropDown2. Note that the dismiss_on_select: False in the kv file is required to be sure that the is2Displayed attribute is updated correctly.
.py:
from kivy.app import App
from kivy.properties import StringProperty
from kivy.uix.dropdown import DropDown
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
class MyScreenManager(ScreenManager):
button_text = StringProperty('Show possibilities')
def __init__(self, **kwargs):
super(MyScreenManager, self).__init__(**kwargs)
self.dropdown = CustomDropDown1(self)
def open_drop_down(self, widget):
self.dropdown.open(widget)
class MyScreen(Screen):
def __init__(self, **kwargs):
super(MyScreen, self).__init__(**kwargs)
class CustomDropDown1(DropDown):
def __init__(self, screen_manager, **kwargs):
super(CustomDropDown1, self).__init__(**kwargs)
self.sm = screen_manager
self.dropdown2 = CustomDropDown2(self.sm)
self.is2Displayed = False
def on_select(self, data):
self.sm.button_text = data
def open_drop2(self):
if not self.is2Displayed:
self.dropdown2.open(self)
self.is2Displayed = True
else:
self.dropdown2.dismiss()
self.is2Displayed = False
class CustomDropDown2(DropDown):
def __init__(self, screen_manager, **kwargs):
super(CustomDropDown2, self).__init__(**kwargs)
self.sm = screen_manager
def on_select(self, data):
self.sm.button_text = data
Builder.load_file("debug.kv")
class MyAppli(App):
def build(self):
return MyScreenManager()
if __name__ == '__main__':
MyAppli().run()
.kv:
<MyScreenManager>:
MyScreen:
FloatLayout:
Button:
text: root.button_text
size: (200, 50)
size_hint:(None,None)
pos_hint: {'center_x': 0.5, 'top': 1.0}
on_release: root.open_drop_down(self)
<CustomDropDown1>:
padding: [0,0,0,0]
Button:
text:"Item 1"
size:(200,50)
size_hint:(None,None)
text_size: self.size
valign: 'center'
padding: (10,0)
on_release: root.select(self.text)
Button:
text:"Item 2"
size:(200,50)
size_hint:(None,None)
text_size: self.size
valign: 'center'
padding: (10,0)
on_release: root.open_drop2()
Button:
text:"Item 3"
size:(200,50)
size_hint:(None,None)
text_size: self.size
valign: 'center'
padding: (10,0)
on_release: root.select(self.text)
<CustomDropDown2>:
dismiss_on_select: False
Button:
text:"Item 1,2"
size:(200,50)
size_hint:(None,None)
text_size: self.size
valign: 'center'
padding: (50,0)
on_release: root.select(self.text)
Button:
text:"Item 2,2"
size:(200,50)
size_hint:(None,None)
text_size: self.size
valign: 'center'
padding: (50,0)
on_release: root.select(self.text)
Button:
text:"Item 3,2"
size:(200,50)
size_hint:(None,None)
text_size: self.size
valign: 'center'
padding: (50,0)
on_release: root.select(self.text)

Related

Kivy FileChooser Overlapping

I am using the FileChooserListView from kivy and have run into a overlapping text on scroll with screens that another user came across as well. I looked through their post on GitHub and read that some people are using the plyer FileChooser. I also saw that someone mentioned that it has to do with the Building function of the .kv file. I created a new kivy app and the problem did not occur, but when I return to my older app (no changes of any kind) the problem still occurs.
Sorry for the long post, but I am unsure how these two kivy app codes are different. Am I calling something twice that is causing the FileChooser to "hold" it's position? I am not oppose to using plyer's FileChooser, but could someone give me an example on how to implement it?
testing_kivy.py
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.popup import Popup
from kivy.properties import ObjectProperty
from kivy.uix.floatlayout import FloatLayout
import os
def train_load(path, filename):
download_path = os.path.join(path, filename[0])
print(download_path)
class LoadDialog(FloatLayout):
load = ObjectProperty(None)
cancel = ObjectProperty(None)
class TrainingWindow(Screen):
def show_load_list(self):
content = LoadDialog(load=train_load, cancel=self.dismiss_popup)
self._popup = Popup(title="Load a file list", content=content, size_hint=(1, 1))
self._popup.open()
def dismiss_popup(self):
self._popup.dismiss()
class WindowManager(ScreenManager):
pass
kv_training = Builder.load_file('testing_kivy.kv')
class MyApp(App):
def build(self):
return kv_training
if __name__ == '__main__':
MyApp().run()
testing_kivy.kv
WindowManager:
TrainingWindow:
<TrainingWindow>
name: "training"
BoxLayout:
orientation: "vertical"
Button:
text: "Select Training Images"
font_size: 32
on_release: root.show_load_list()
Button:
text: "Select Training Annots"
font_size: 32
on_release: root.show_load_list()
Button:
text: "Set Parameters"
font_size: 32
on_release:
app.root.current = "parameters_train"
root.manager.transition.direction = "up"
Button:
text: "Back"
font_size: 16
on_release:
app.root.current = "select"
root.manager.transition.direction = "right"
<LoadDialog>:
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserListView:
id: filechooser
BoxLayout:
size_hint_y: None
height: 30
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Load"
on_release: root.load(filechooser.path, filechooser.selection)
Older_app.py
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.spinner import SpinnerOption
import os
import pandas as pd
def invalid_login():
app = App.get_running_app()
app.root.current = "main"
# Create a BoxLayout to add multiple lines or buttons to a PopUp
box = BoxLayout()
# Create PopUp
pop = Popup(
title="Invalid Password",
size_hint=(None, None), size=(200, 100),
content=box,
auto_dismiss=False
)
# Dismiss PopUp
box.add_widget(Button(text="Close", on_release=pop.dismiss))
pop.open()
def model_load(path, filename):
download_path = os.path.join(path, filename[0])
print(download_path)
def train_load(path, filename):
download_path = os.path.join(path, filename[0])
print(download_path)
def train_model_load(path, filename):
download_path = os.path.join(path, filename[0])
print(download_path)
class MainWindow(Screen):
def login(self):
if self.ids.password.text == "password":
self.ids.password.text = ""
app = App.get_running_app()
app.root.current = "select"
else:
self.ids.password.text = ""
invalid_login()
class SelectWindow(Screen):
pass
class LoadDialog(FloatLayout):
load = ObjectProperty(None)
cancel = ObjectProperty(None)
class TrainingWindow(Screen):
def show_load_list(self):
content = LoadDialog(load=train_load, cancel=self.dismiss_popup)
self._popup = Popup(title="Load a file list", content=content, size_hint=(1, 1))
self._popup.open()
def dismiss_popup(self):
self._popup.dismiss()
class ModelWindow(Screen):
def show_load_list(self):
content = LoadDialog(load=model_load, cancel=self.dismiss_popup)
self._popup = Popup(title="Load a file list", content=content, size_hint=(1, 1))
self._popup.open()
def dismiss_popup(self):
self._popup.dismiss()
class TrainModelWindow(Screen):
def show_load_list(self):
content = LoadDialog(load=train_model_load, cancel=self.dismiss_popup)
self._popup = Popup(title="Load a file list", content=content, size_hint=(1, 1))
self._popup.open()
def dismiss_popup(self):
self._popup.dismiss()
class ParametersTrainModelWindow(Screen):
pass
class ParametersTrainWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
class OverViewTrainWindow(Screen):
pass
class OverViewTrainModelWindow(Screen):
pass
class OverViewModelWindow(Screen):
pass
class MyOption(SpinnerOption):
pass
kv_main= Builder.load_file('main.kv')
class MyApp(App):
def build(self):
return kv_main
if __name__ == '__main__':
MyApp().run()
main.kv
#:import utils kivy.utils
#:include select.kv
#:include training.kv
#:include model.kv
#:include train_model.kv
#:include parameters_train.kv
#:include parameters_train_model.kv
#:include overview_train_model.kv
#:include overview_train.kv
#:include overview_model.kv
WindowManager:
MainWindow:
SelectWindow:
TrainingWindow:
ModelWindow:
TrainModelWindow:
ParametersTrainWindow:
ParametersTrainModelWindow
OverViewTrainWindow:
OverViewTrainModelWindow:
OverViewModelWindow:
<MainWindow>
name: "main"
GridLayout:
cols: 1
BoxLayout:
orientation: "vertical"
canvas.before:
Color:
rgba: 0,0,0,1
Rectangle:
pos: self.pos
size: self.size
Label:
size_hint: 1, 1
text: "SPECPHASE"
font_size: 50
color:
utils.get_color_from_hex('#FF0000')
Label:
size_hint: 1, 1
text: "Object Detection App"
font_size: 40
BoxLayout:
size_hint: 1, 0.005
canvas.before:
Color:
rgba: (1,1,1,1)
Rectangle:
size: self.size
pos: self.pos
BoxLayout:
orientation: "horizontal"
size_hint: (0.35, 0.35)
padding: (0,0,25,0)
Label:
font_size: 20
text: "Password"
size_hint: (0.5, 0.35)
pos_hint: {'x': 1, 'y': 0.4}
background_color: (0,0,0,1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
TextInput:
id: password
multiline: False
size_hint: (0.5, 0.35)
pos_hint: {'x': 1, 'y': 0.4}
focus: True
background_color:
utils.get_color_from_hex('#18B8D9')
cursor_color: (0,0,0,1)
password: True
Button:
text: "Submit"
on_release: root.login()
select.kv
<SelectWindow#Screen>:
name: "select"
GridLayout:
cols: 1
GridLayout:
cols: 2
Button:
text: "Train"
font_size: 32
on_release:
app.root.current = "training"
root.manager.transition.direction = "right"
Button:
text: "Model"
font_size: 32
on_release:
app.root.current = "model"
root.manager.transition.direction = "left"
Button:
text: "Train & Model"
font_size: 32
on_release:
app.root.current = "train_model"
root.manager.transition.direction = "up"
training.kv
<TrainingWindow#Screen>:
name: "training"
BoxLayout:
orientation: "vertical"
Button:
text: "Select Training Images"
font_size: 32
on_release: root.show_load_list()
Button:
text: "Select Training Annots"
font_size: 32
on_release: root.show_load_list()
Button:
text: "Set Parameters"
font_size: 32
on_release:
app.root.current = "parameters_train"
root.manager.transition.direction = "up"
Button:
text: "Back"
font_size: 16
on_release:
app.root.current = "select"
root.manager.transition.direction = "right"
<LoadDialog>:
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserListView:
id: filechooser
BoxLayout:
size_hint_y: None
height: 30
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Load"
on_release: root.load(filechooser.path, filechooser.selection)
After taking a break from this for while and restarting my brain, I was able to find the problem.
Not included in my question, I have a couple more .kv files that have a similar layout to the training.kv. They are used to access other screens. I found that I was calling FileChooserListView in each screen and I belive that is why I was seeing the stacking problem. I ended up removing all of them except for the one in my training.kv file and all is working.

How to switch screens from a dynamically created button in kivy recycleview

Problem
I have a screen (OrderScreen) that populates with buttons if there is data to be processed. I would like the user to click one of the buttons to be brought to another screen (MenuScreen) to process the data. While my intention is to populate the next screen with data from the button, I am currently just trying to get the ScreenManager to change to the next screen after a button press. I added a pass_data() method to the OrderButton and tried to trigger the screen manager there but self.manager.current and root.manager.current were throwing exceptions. Any help would be greatly appreciated.
recycleview_test.py
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.recycleview import RecycleView
from kivy.uix.screenmanager import ScreenManager, Screen
from random import randint
class MenuScreen(Screen):
def quit(self):
App.get_running_app.stop()
Window.close()
class OrderScreen(Screen):
pass
class OrderButton(Button):
def __init__(self, **kwargs):
super(OrderButton, self).__init__(**kwargs)
def pass_data(self):
print("button pushed")
class OrderScroll(RecycleView):
def __init__(self, **kwargs):
super(OrderScroll, self).__init__(**kwargs)
self.data = [{'text': str(f"Make {randint(10, 25)} items from package #{randint(1,4)}")} for x in range(12)]
class WindowManager(ScreenManager):
pass
class RecycleApp(App):
def build(self):
return WindowManager()
if __name__ == "__main__":
RecycleApp().run()
recycle.kv
#:import Factory kivy.factory.Factory
#: import ScreenManager kivy.uix.screenmanager.ScreenManager
#: import Screen kivy.uix.screenmanager.ScreenManager
#:import App kivy.app.App
<OrderScroll>:
viewclass: 'OrderButton'
manager: None
RecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
padding: 20
spacing: 10
<OrderButton>:
manager: None
font_size: 32
bold: True
on_release:
root.pass_data()
<WindowManager>:
id: screen_manager
OrderScreen:
id: order_screen
name: "OrderScreen"
manager: screen_manager
MenuScreen:
id: menu_screen
name: 'MenuScreen'
manager: screen_manager
<OrderScreen>:
BoxLayout:
orientation: "vertical"
Label:
text: "Data Buttons"
font_size: 64
size_hint_y: None
# pos_hint: {"x":0, "y":1}
height: 200
OrderScroll:
<MenuScreen>:
BoxLayout:
orientation: "vertical"
Label:
text: "Made it"
font_size: 64
FloatLayout:
Button:
text: 'Keep going'
font_size: 48
size_hint: .8,.5
pos_hint: {"center_x": .5, "center_y": .1}
FloatLayout:
Button:
text: 'Quit'
size_hint: .15,.3
pos_hint: {"center_x": .5, "center_y": .5}
on_release:
root.quit()
Try to create an object of screen manager:
class RecycleApp(App):
def build(self):
self.sm = WindowManager()
return self.sm
And then access it by:
App.get_running_app().sm.current = 'MenuScreen' # in Python
app.sm.current = 'MenuScreen' # in kv

Python/Kivy : Remove space using python

I am using python-2.7 and kivy. I am trying to hide TextInput with blank space.
At this time i am using opacity property for hiding Textinput
self.row.abc.opacity = 0
Using this code TextInput is hiding but blank space not removed. Can someone tell me how to remove blank space or another better solution for hiding Textinput with blank space.
test.py
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty, StringProperty, ObjectProperty
Window.size = (450, 425)
class display(Screen):
def __init__(self, **kwargs):
super(display, self).__init__(**kwargs)
def add_more(self):
self.ids.rows.add_row()
class Row(BoxLayout):
button_text = StringProperty("")
id = ObjectProperty(None)
col_data = ListProperty(["", ""])
class Rows(BoxLayout):
orientation = "vertical"
row_count = 0
def __init__(self, **kwargs):
super(Rows, self).__init__(**kwargs)
self.add_row()
def add_row(self):
self.row_count += 1
self.row = Row(button_text=str(self.row_count))
self.row.abc.opacity = 0
self.row.col_data[1] = 'Test1'
self.add_widget(self.row)
class test(App):
def build(self):
return self.root
if __name__ == '__main__':
test().run()
test.kv
<Row>:
abc: abc
#state1 : state1
orientation: "horizontal"
spacing: 0, 5
Button:
text: root.button_text
size_hint_x: .2
TextInput:
id : abc
size_hint_x: .8
text : root.col_data[0]
TextInput:
size_hint_x: .8
text : root.col_data[1]
display:
BoxLayout:
orientation: "vertical"
padding : 20, 20
BoxLayout:
orientation: "horizontal"
Button:
size_hint_x: .2
text: "+Add More"
valign: 'bottom'
on_press: root.add_more()
BoxLayout:
orientation: "horizontal"
Label:
size_hint_x: .2
text: "SN"
valign: 'bottom'
Label:
size_hint_x: .8
text: "Value1"
valign: 'bottom'
Label:
size_hint_x: .8
text: "Value2"
valign: 'bottom'
Rows:
id: rows

python/kivy : set dynamically value on on_touch_down event in TextInput from treeView

I have two files test1.py and test1.kv. There are a +Add more button.When click on +Add More button then row add dynamic.
I added treeView on TextInput.But now i am confused that how to put selected treeView value(self.text) in current TextBox because every TextBox added dynamic so i don't know how to set selected treeView value in current TextBox
test1.py
import kivy
kivy.require('1.9.0') # replace with your current kivy version !
import sqlite3 as lite
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty, NumericProperty
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.core.window import Window
from kivy.uix.label import Label
from kivy.clock import Clock
from kivy.uix.treeview import TreeView, TreeViewLabel, TreeViewNode
from kivy.uix.screenmanager import Screen
Window.size = (450, 525)
class TreeviewNumber(Popup):
treeview = ObjectProperty(None)
tv = ObjectProperty(None)
h = NumericProperty(0)
def __init__(self, **kwargs):
super(TreeviewNumber, self).__init__(**kwargs)
self.tv = TreeView(root_options=dict(text=""),
hide_root=False,
indent_level=4)
rows = [('One'), ('Two'), ('Three')]
tree = []
for r in rows:
tree.append({'node_id': r, 'children': []})
for branch in tree:
populate_tree_view(self.tv, None, branch)
#self.remove_widgets()
self.treeview.add_widget(self.tv)
Clock.schedule_once(self.update, 1)
def remove_widgets(self):
for child in [child for child in self.treeview.children]:
self.treeview.remove_widget(child)
def update(self, *args):
self.h = len([child for child in self.tv.children]) * 24
def populate_tree_view(tree_view_city, parent, node):
if parent is None:
tree_node = tree_view_city.add_node(TreeViewLabel(text=node['node_id'],
is_open=True))
else:
tree_node = tree_view_city.add_node(TreeViewLabel(text=node['node_id'],
is_open=True), parent)
for child_node in node['children']:
populate_tree_view(tree_view_city, tree_node, child_node)
class TreeViewLabel(Label, TreeViewNode):
pass
class display(Screen):
def add_more(self):
self.ids.rows.add_row()
def insert_value(self):
#print(Row().id)
w = Row()
print(w.ids.state.text)
class Row(BoxLayout):
button_text = StringProperty("")
state = ObjectProperty('')
popupNumber = ObjectProperty(None)
popup_number = ObjectProperty(None)
def display_number(self,instance):
if self.popupNumber is None:
# if self.popupAccountCity is None:
self.popupNumber = TreeviewNumber()
self.popupNumber.popup_number = self
self.popupNumber.open()
class Rows(BoxLayout):
orientation = "vertical"
row_count = 0
button_text = StringProperty("")
def __init__(self, **kwargs):
super(Rows, self).__init__(**kwargs)
self.add_row()
def add_row(self):
self.row_count += 1
self.add_widget(Row(button_text=str(self.row_count),id=str("test"+str(self.row_count))))
class test(App):
def build(self):
self.root = Builder.load_file('test1.kv')
return self.root
if __name__ == '__main__':
test().run()
test1.kv
<Row>:
state : state
orientation: "horizontal"
spacing: 0, 5
Button:
text: root.button_text
size_hint_x: .2
TextInput:
#text : root.id
size_hint_x: .8
id : state
on_focus: root.display_number(self)
display:
BoxLayout:
orientation: "vertical"
padding : 20, 20
BoxLayout:
orientation: "horizontal"
Button:
size_hint_x: .2
text: "+Add More"
valign: 'bottom'
on_press: root.add_more()
BoxLayout:
orientation: "horizontal"
Label:
size_hint_x: .2
text: "SN"
valign: 'bottom'
Label:
size_hint_x: .8
text: "Value"
valign: 'bottom'
Rows:
id: rows
BoxLayout:
orientation: "horizontal"
padding : 10, 0
spacing: 10, 10
size_hint: .5, .7
pos_hint: {'x': .25, 'y':.25}
Button:
text: 'Ok'
on_release:
root.insert_value()
Button:
text: 'Cancel'
on_release: root.dismiss()
<TreeviewNumber>:
treeview: treeview
title: "Select Number"
title_size: 17
title_font: "Verdana"
#pos_hint: {'x': .62, 'y': .55}
size_hint: .5, .5
auto_dismiss: False
BoxLayout
orientation: "vertical"
ScrollView:
size_hint: 1, .9
BoxLayout:
size_hint_y: None
id: treeview
#height: root.h
#rooot: root
GridLayout:
cols : 2
row_default_height: '20dp'
size_hint: .5, 0.2
pos_hint: {'x': .25, 'y': 1}
Button:
text: 'Ok'
on_release: root.dismiss()
Button:
text: 'Cancel'
on_release: root.dismiss()
<TreeViewLabel>:
text_size: self.size
height: 24
on_touch_down:
print(self.text)

Python/Kivy : How to pass TextBox value in .kv file from one class to another class

Can anyone tell me?
I have two file test.py and test.kv.
I have a textBox which id : state . How to pass state.text value in root.get_value(state.text) and get value in function of def get_value
test.py
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty, NumericProperty
Window.size = (450, 525)
class display(Screen):
state = ObjectProperty(None)
def add_more(self):
self.ids.rows.add_row()
def get_value(self,arg1):
print(arg1)
class Row(BoxLayout):
button_text = StringProperty("")
state = ObjectProperty(None)
class Rows(BoxLayout):
orientation = "vertical"
row_count = 0
def __init__(self, **kwargs):
super(Rows, self).__init__(**kwargs)
self.add_row()
def add_row(self):
self.row_count += 1
self.add_widget(Row(button_text=str(self.row_count)))
class test(App):
def build(self):
self.root = Builder.load_file('test.kv')
return self.root
if __name__ == '__main__':
test().run()
test.kv
<Row>:
state : state
orientation: "horizontal"
spacing: 0, 5
Button:
text: root.button_text
size_hint_x: .2
TextInput:
text : "Test1"
size_hint_x: .8
id : state
display:
BoxLayout:
orientation: "vertical"
padding : 20, 20
BoxLayout:
orientation: "horizontal"
Button:
size_hint_x: .2
text: "+Add More"
valign: 'bottom'
on_press: root.add_more()
BoxLayout:
orientation: "horizontal"
Label:
size_hint_x: .2
text: "SN"
valign: 'bottom'
Label:
size_hint_x: .8
text: "Value"
valign: 'bottom'
Rows:
id: rows
BoxLayout:
orientation: "horizontal"
padding : 10, 0
spacing: 10, 10
size_hint: .5, .7
pos_hint: {'x': .25, 'y':.25}
Button:
text: 'Ok'
on_release:
root.get_value(state.text)
Button:
text: 'Cancel'
on_release: root.dismiss()

Categories

Resources