I am dynamically creating buttons and dynamically creating a dropdown for each button. when the button is selected the text value updates on the main button. I want to get the
Use on_select event to pass the selected text to the method. Please refer to the snippets and example for details.
<CustomDropDown>:
on_select:
app.root.ids.Notes.ids.mainbutton.text = '{}'.format(args[1])
app.root.Run_Draws_Test(args[1])
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
from kivy.core.window import Window
Window.size = (800, 480)
class CustomDropDown(DropDown):
def __init__(self, **kwargs):
super(CustomDropDown, self).__init__(**kwargs)
self.add_buttons()
def add_buttons(self):
for index in range(10):
# When adding widgets, we need to specify the height manually
# (disabling the size_hint_y) so the dropdown can calculate
# the area it needs.
btn = Button(text='Value %d' % index, size_hint_y=None, height=44)
# for each button, attach a callback that will call the select() method
# on the dropdown. We'll pass the text of the button as the data of the
# selection.
btn.bind(on_release=lambda btn: self.select(btn.text))
# then add the button inside the dropdown
self.add_widget(btn)
class Notes(Screen):
pass
class MyScreenManager(ScreenManager):
def Run_Draws_Test(self, value):
print(value)
class TestApp(App):
title = "Kivy Drop-Down List Demo"
def build(self):
return MyScreenManager()
if __name__ == '__main__':
TestApp().run()
#:kivy 1.10.0
#:import Factory kivy.factory.Factory
<CustomDropDown>:
on_select:
app.root.ids.Notes.ids.mainbutton.text = '{}'.format(args[1])
app.root.Run_Draws_Test(args[1])
<Notes>:
orientation: "vertical"
FloatLayout:
size_hint: None, None
canvas.before:
Color:
rgba: 1, 1, 0, 1
Button:
id: mainbutton
text: "Menu name"
font_size: 20
size_hint: None, None
size: 150, 50
pos: 20,400
on_release: Factory.CustomDropDown().open(self)
<MyScreenManager>:
canvas.before:
Color:
rgba: 0.5, 0.5, 0.5, 0.5
Rectangle:
pos: 0,0
size: 800, 480
Notes:
id:Notes
name: 'Notes'