Thursday, July 4, 2024
HomeLanguagesPythonKivy – Material design Icon button

Kivy – Material design Icon button

Kivy is a platform-independent GUI tool in Python. It can run on Android, IOS, Linux and Windows, etc. This is the only GUI library from python which can independently run on an android device even we can use it on Raspberry pi also.  It is an open-source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. Its graphic engine is built over OpenGL ES 2 and has fast graphics pipeline. 

In this article, we will develop a GUI window using kivy framework of python, and we will add material design icon buttons of different sizes on this window.

Approach:

  • Import required modules.
  • Create an App class.
  • Add Buttons.
  • Return layout.
  • Run an instance of the class.

Implementation:                  

Python3




# importing mdapp from kivymd framework
from kivymd.app import MDApp
  
# importing builder from kivy
from kivy.lang import Builder
  
# this is the main class which
# will render the whole application
class uiApp(MDApp):
  
    # method which will render our application
    def build(self):
        return Builder.load_string("""
  
MDBoxLayout:
    spacing:300
    MDIconButton:
      
        # name of mdicon
        icon:"language-python"                          
        pos_hint: {"center_x": .5, "center_y": .5}
        user_font_size: "64sp"
          
        # bgcolor of iconbutton
        md_bg_color:[1,1,0,1]                           
      
    MDIconButton:
          
        # custom image as mdicon
        icon:"gfg.png"                                  
        pos_hint: {"center_x": .5, "center_y": .5}
        user_font_size: "16sp"
          
    MDIconButton:
          
        icon:"language-python"
        pos_hint: {"center_x": .5, "center_y": .5}
  
                                   """)
  
# running the application
uiApp().run()


Output:

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments