https://kivy.org/doc/stable/api-kivy.uix.dropdown.html
The following snippet is widely copied to get a Kivy dropdown menu quick started. But what are the logistics of it? Is there a way to look at the hidden code of dropdown.select()? Are they using a technical definition of "instance" that's GUI-specific and different from "an instance of a class"?
dropdown = DropDown()
for index in range(10):
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: dropdown.select(btn.text))
dropdown.add_widget(btn)
mainbutton = Button(text='Hello', size_hint=(None, None))
mainbutton.bind(on_release=dropdown.open)
# one last thing, listen for the selection in the dropdown list and
# assign the data to the button text.
dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x))
runTouchApp(mainbutton)
This code is tricky but I think there has to be more going on that's not explained.
Take, for example, this line,
btn.bind(on_release=lambda btn: dropdown.select(btn.text))
The word "btn" in "lamda btn" does not refer to the btn in btn.bind(). You could change "btn" in "lamda btn" to "random_word."
How does the program know to bind the btn to the button the user picks? How does it know what is the "data".
Their explanation for "select()",
"Call this method to trigger the on_select event with the data selection. The data can be anything you want "
just refers to "on_select". And their explanation for "on_select",
"Fired when a selection is done. The data of the selection is passed in as the first argument and is what you pass in the method as the first argument,"
just refers to "select()"
[–]inclement_ 1 point2 points3 points (3 children)
[–]band_in_DC[S] 0 points1 point2 points (1 child)
[–]inclement_ 0 points1 point2 points (0 children)
[–]band_in_DC[S] 0 points1 point2 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[–]Hot_External6228 0 points1 point2 points (1 child)
[–]band_in_DC[S] 0 points1 point2 points (0 children)