KivyMD
KivyMD copied to clipboard
MDDropdownMenu Position isn't working after second time
After second click on the Button the MDDropdownMenu Position isn't working (position="bottom").
from kivymd.app import MDApp
from kivy.lang import Builder
from kivymd.uix.menu import MDDropdownMenu
from kivy.utils import hex_colormap
from kivy.metrics import dp
from kivymd.uix.navigationbar import (
MDNavigationBar,
MDNavigationItem,
MDNavigationItemLabel,
MDNavigationItemIcon,
)
from kivymd.uix.button import (
MDIconButton,
MDButton,
MDFabButton,
MDButtonText,
MDButtonIcon,
MDExtendedFabButton,
MDExtendedFabButtonIcon,
MDExtendedFabButtonText,
)
KV = """
MDScreen:
md_bg_color: self.theme_cls.backgroundColor
MDBoxLayout:
id: root_box
orientation: "vertical"
MDTopAppBar:
id: appbar
type: "small"
pos_hint: {"center_x": 1.3}
MDTopAppBarTrailingButtonContainer:
MDActionTopAppBarButton:
icon: "menu"
#on_release: app.open_menu(self)
ScrollView:
MDBoxLayout:
id: root_box
orientation: "vertical"
adaptive_height: True
padding: 40
spacing: 10
MDButton:
id: button_menu
style: "filled"
radius: 6
theme_width: "Custom"
size_hint: (1, None)
on_release: app.button_menu(self)
MDButtonText:
#id: button_menu
text: "Open Menu"
pos_hint: {"center_x": .5, "center_y": .5}
font_size: '60dp'
MDButton:
id: button_menu2
style: "filled"
radius: 6
theme_width: "Custom"
size_hint: (1, None)
on_release: app.button_menu2(self)
MDButtonText:
#id: button_menu
text: "Open Menu"
pos_hint: {"center_x": .5, "center_y": .5}
font_size: '60dp'
"""
from kivy.core.window import Window
Window.size = (400, 600)
Window.top = 150
Window.left = 850
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
super().on_start()
available_palettes = [
name_color.capitalize() for name_color in hex_colormap.keys()
]
menu_items = []
for name_palette in available_palettes:
menu_items.append(
{
"text": name_palette,
#"on_release": lambda x=name_palette: self.switch_palette(x),
}
)
self.menu_down = MDDropdownMenu(
caller=self.root.ids.button_menu,
items=menu_items,
max_height=dp(600),
position="bottom",
ver_growth="down",
)
self.menu_down2 = MDDropdownMenu(
caller=self.root.ids.button_menu2,
items=menu_items,
position="bottom",
ver_growth="down",
)
def button_menu(self, instance_from_menu):
self.menu_down.open()
def button_menu2(self, instance_from_menu):
self.menu_down2.open()
Test().run()
https://github.com/kivymd/KivyMD/assets/3679001/12ab3264-abec-4d18-bc5c-e260bb9fa3a0