OK. :-) Your code works fine as a standalone. But when I insert it in my app, and call it from a BoxLayout like this:
class ChooseTarget(BoxLayout):
(...)
def no_no(self):
# User will choose a target from a list
self.clear_widgets()
# I try Elliot's example that DID work as a standalone:
self.mydropdown = ButtonDropDown()
I get a strange error on the 'dropdown.open':
File "/mnt/4AF15A0435E762B4/mypython/GeoESP/main.py", line 1612, in delayed_open
self.dropdown.open(self) # open the dropdown
File "/mnt/4AF15A0435E762B4/mypython/GeoESP-android/newvenv/lib/python3.8/site-packages/kivy/uix/dropdown.py", line 246, in open
raise DropDownException(
kivy.uix.dropdown.DropDownException: Cannot open a dropdown list on a hidden widget
I even tried delaying 'open' using Clock (similar to your code), but that didn't change anything:
self.dropdown.bind(on_select=lambda instance, x: setattr(self, 'text', x))
Clock.schedule_once(self.delayed_open)
def delayed_open(self, _):
self.dropdown.open(self) # open the dropdown
Here is your DropDown code. I only changed height=dp(48) to height=48 in Button:
class ButtonDropDown(Button): # ScalableButton
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.dropdown = DropDown()
Clock.schedule_once(self.add_buttons)
def add_buttons(self, _):
for i in range(10):
button = Button(text=f'Item {i}', size_hint_y=None, height=48)
button.bind(on_release=lambda btn: self.dropdown.select(btn.text))
self.dropdown.add_widget(button)
self.bind(on_release=self.dropdown.open)
self.dropdown.bind(on_select=lambda instance, x: setattr(self, 'text', x))
# Clock.schedule_once(self.delayed_open)
# def delayed_open(self, _):
self.dropdown.open(self) # open the dropdown
Do you have any idea about what goes wrong?
Love,
Henrik
PS: I am away on holiday for a week, starting tomorrow (Saturday).