Skip to content

Instantly share code, notes, and snippets.

@gottadiveintopython
Last active August 23, 2024 23:29
Show Gist options
  • Select an option

  • Save gottadiveintopython/c59044b578aaac4eb8b4193716d8421b to your computer and use it in GitHub Desktop.

Select an option

Save gottadiveintopython/c59044b578aaac4eb8b4193716d8421b to your computer and use it in GitHub Desktop.
Listing all icons available on KivyMD. You can easily see the name of an icon by pressing it.
'''
pip install kivy kivymd
'''
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.snackbar.snackbar import MDSnackbar
KV_CODE = '''
#:import md_icons kivymd.icon_definitions.md_icons
#:set FONT_SIZE 64
RecycleView:
viewclass: 'Item'
data:
[{
'font_style': 'Icon',
'text': value,
'icon_name': key,
'halign': 'center',
'font_size': FONT_SIZE,
} for key, value in md_icons.items()]
RecycleGridLayout:
cols: root.width // FONT_SIZE
size_hint_y: None
height: self.minimum_height
default_size: FONT_SIZE, FONT_SIZE
default_size_hint: None, None
'''
class Item(MDLabel):
icon_name = StringProperty()
def on_touch_down(self, touch):
if self.collide_point(*touch.opos):
MDSnackbar(MDLabel(text=self.icon_name), duration=0.5).open()
class ListingAllIconsApp(MDApp):
def build(self):
return Builder.load_string(KV_CODE)
if __name__ == '__main__':
ListingAllIconsApp().run()
@zhuchangzhan

Copy link
Copy Markdown

Kivymd seen some updates, inorder for this to work, please do the below:

Small changes to import

from kivymd.uix.label import MDLabel
from kivymd.uix.snackbar import Snackbar

Add this to import:
from kivymd.app import MDApp

change line 39 - 40 to below:

class ListAllIconsApp(MDApp):

def __init__(self, **kwargs):
    super().__init__(**kwargs)
    theme_cls = ThemeManager()

@gottadiveintopython

Copy link
Copy Markdown
Author

I'll fix it later, 謝謝你!

@zhuchangzhan

Copy link
Copy Markdown

I'll fix it later, 謝謝你!
Thank you for the awesome tool btw.

@LiamFrance

Copy link
Copy Markdown

show() is not available with snackbar anymore, currently is open(). Anyway thanks for great tool

@gottadiveintopython

Copy link
Copy Markdown
Author

@LiamFrance Fixed. Thanks.

@brrrrice

brrrrice commented Aug 23, 2024

Copy link
Copy Markdown

Hi, this is a useful piece of code !
To make it work with more recent kivy :
from kivymd.uix.snackbar.snackbar import MDSnackbar
and
MDSnackbar(MDLabel(text=self.icon_name), duration=0.5).open()

@gottadiveintopython

Copy link
Copy Markdown
Author

@brrrrice Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment