Create Label or Text in Python with kivyMd
July 09, 2020
First Program in KivyMd
Today, I have solve my previous problems permanentSo lets Create our first Text Program With kivymd
I will Write First code Then explain then image
Note: Need Basic Knowldge of Python(compulsory) and kivy before reading this tutorial.
Step 1: Write A Program (WAP) in kivymd to Create app screen with title Demo
Code:-->
from kivymd.app import MDAppclass DemoApp(MDApp):def build(self):returnDemoApp().run()
Explain :-->
Line 1:--> To imoprt kivmd package as MDApp .
Line 2:--> To create a class means a group of function and specifics program. Your Class name will show as App Title. MDApp is telling this program written with kivymd package.
Line 3:--> Create A Function With build make sure b will not write as B it will become cause of error.
self to tell start automatic when class got call.
Line 4:--> Return Nothing and display empty app window
Line 5:--> Call DemoApp class to run from there
Step 2: WAP in kivymd to create text with hello, Dear Friend
Code:-->
from kivymd.app import MDAppfrom kivymd.uix.label import MDLabel
class DemoApp(MDApp):def build(self):return MDLabel(text="Hello, Dear Friend")DemoApp().run()
Explain:-->
Line 2:--> kivymd package name, uix include all user interface related parameters like button, text, color, size and more.
Note:--> All kivymd function start with MD like
in kivy
App, Label, Button, etc.,
kivymd
MDApp, MDLabel, MDButton, etc.,
All MDLabel Parameter and Attribute List and Use.
Complete: --> WAP in kivymd to create colorful text with center align (blue)
Code:-->
from kivymd.app import MDAppfrom kivymd.uix.label import MDLabelclass DemoApp(MDApp):def build(self):label = MDLabel(text="Hello, Dear", halign="center", font_style="H1", theme_text_color="error")return labelDemoApp().run()
replace to create custom color with RGBA Property
label = MDLabel(text="Hello, Dear", halign="center", font_style="H1", theme_text_color="custom", text_color=(10,10,10,1))