[kivy-users] Kivymd menu left padding, height and font size change problem

154 views
Skip to first unread message

Mr. Mog

unread,
Jan 24, 2021, 7:27:14 AM1/24/21
to kivy-...@googlegroups.com
Hello everybody,

I am trying to have a customized kivymd menu, with my own left padding, item height, and font size.

I tried this:

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.menu import MDDropdownMenu

kv = '''
FloatLayout:
 MDRaisedButton:
  id: but
  text: "Menu"
  pos_hint: {"center_x":.5, "center_y":.8}
  on_release: app.menu.open()
  
'''

class MyApp(MDApp):
 def __init__(self, **kwargs):
  super().__init__(**kwargs)
  
  self.screen = Builder.load_string(kv)
  
  self.list = ["Copy", "Cut","Bold", "Highlight"]
  
  self.data = []
  
  for i in self.list:
   self.data.append(
   {"text": f"{i}",
   # this doesn't work
   "height": "20dp",
   "divider": None,
   "top_pad": "10dp",
   "bot_pad": "10dp",
   # this doesn't work
   "left_pad": "0dp",
   })
  
  
  self.menu = MDDropdownMenu(
  items=self.data,
  caller = self.screen.ids.but, 
  border_margin=0,
  width_mult=2,)
 def build(self):
  return self.screen
  
MyApp().run()

How do I change the menu item height, padding and font size?

Elliot Garbus

unread,
Jan 24, 2021, 10:55:00 AM1/24/21
to kivy-...@googlegroups.com

Looking at the source code, you can change the padding and the height.   You cannot change the font_size.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAGpYEywNJw8%3D%2BMLDU6Nr7WHDaeCCRo88_%3DrfAKoprTHvFeDXYQ%40mail.gmail.com.

 

Mr. Mog

unread,
Jan 24, 2021, 11:15:41 AM1/24/21
to kivy-...@googlegroups.com

Elliot Garbus

unread,
Jan 24, 2021, 11:17:26 AM1/24/21
to kivy-...@googlegroups.com

I created a version starting with the example in the docs and can adjust the padding.

 

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.menu import
MDDropdownMenu

KV =
'''
Screen:

    MDRaisedButton:
        id: button
        text: "PRESS ME"
        pos_hint: {"center_x": .5, "center_y": .5}
        on_release: app.menu.open()
'''


class Test(MDApp):
   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
       
self.screen = Builder.load_string(KV)
        menu_items = [{
"text": i, "divider": None,"height": "60dp",
                       
"top_pad": "10dp", "bot_pad": "10dp", "left_pad": "5dp", }
                     
for i in ["Copy", "Cut", "Bold", "Highlight"]]

       
self.menu = MDDropdownMenu(caller=self.screen.ids.button,
                                  
items=menu_items, width_mult=4)
       
self.menu.bind(on_release=self.menu_callback)

   
def menu_callback(self, instance_menu, instance_menu_item):
        instance_menu.dismiss()

   
def build(self):
       
return self.screen


Test().run()

Mr. Mog

unread,
Jan 24, 2021, 11:26:47 AM1/24/21
to kivy-...@googlegroups.com
But I also expect it to work by doing that but it just can't work...
Is this a bug?

Elliot Garbus

unread,
Jan 24, 2021, 11:43:19 AM1/24/21
to kivy-...@googlegroups.com

What can’t work.  As I change the padding values, I see a change.

Mr. Mog

unread,
Jan 24, 2021, 12:08:10 PM1/24/21
to kivy-...@googlegroups.com
I can see a little chance in padding but I want more 'cause I want the menu to have width_mult = 2...this plus small font size for items text and the item height.

This is a close code of how I want it to be:

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.menu import MDDropdownMenu

KV = '''
Screen:

    MDRaisedButton:
        id: button
        text: "PRESS ME"
        pos_hint: {"center_x": .5, "center_y": .5}
        on_release: app.menu.open()
'''


class Test(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.screen = Builder.load_string(KV)
        menu_items = [{"text": i, "divider": None,
            "height": "60dp","top_pad": "10dp",
            "bot_pad": "10dp",
            # The left_pad, font_size, width_mult and item height should be as small as possible 'cause this a mobile
            "left_pad": "5dp",
            "font_size": "30", 
            "height": "50dp" }
            for i in ["Copy", "Cut", "Bold", "Highlight"]]

        self.menu = MDDropdownMenu(caller=self.screen.ids.button,
                                   items=menu_items, width_mult=2)
        self.menu.bind(on_release=self.menu_callback)

    def menu_callback(self, instance_menu, instance_menu_item):
        instance_menu.dismiss()

    def build(self):
        return self.screen


Test().run()


Reply all
Reply to author
Forward
0 new messages