Python kivy examples

Python kivy examples: Kivy depends on many Python libraries, such as pygame, gstreamer, PIL, Cairo, and more. They are not all required, but depending on the platform you’re working on, they can be a pain to install. The example for the python kivy is as follows.

Python kivy Examples:-

From kivy.uix.gridlayout import GridLayout
From kivy.uix.label import Label
From.kivy.label import TextInput
Class loginScreen (GridLayout):
Def__init__ (self, **kwargs):
Super(loginScreen, self).__init__ (**kwargs)
Self.cols=2
Self.add_widget (Label (text=’User Name’))
Self.username=TextInput (multiline=False)
Self.add_widget (self.username)
Self.add_widget (Label (‘text=’password’))
Self.password=TextInput (password=True, multiline=False)
Self.add_widget (self.password)
Class MyApp(App):
Def build (self):
Return LoginScreen ()
If__name__==’__main__’:
MyApp ().run ()
From kivy.uix.gridlayout import GridLayout
The class is used as the base for Root Widget as line 9
Class LoginScreen (GridLayout):
Here at line class LoginScreen we override the method then add widget and define,
Def__init___ (self, **kwargs):
Super (LoginScreen, self).__init__ (**kwargs)
Self.cols=2

python kivy examples

Simple App by Using Python Kivy:-

The label will move with multi-touch and even resize the label.
From kivy.app import App
From kivy.uix.scatter import Scatter
From kivy.uix.label import Label
From kivy.uix.floatLayout import FloatLayout
Class SimpleApp (App):
Def build (self):
F=FloatLayout ()
S=Scatter()
L=Label (text=”Edureka!”, font_size=150)
f.add_widget(s)
s.add_widget (1)
return f
if__name__==”__main__”:
simpleApp ().run ()
Output:-
kivy examples

Kivy Widgets:-

From kivy.app import App
From kivy.uix.button import Button
Class Hello (App):
Def.build (self):
btn=Button (text=’Hello world’)
Return btn
Hello ().run ()
python kivy example

Adding More Widgets:-

Add the widgets and code is written by modifying the names as,
Class MyGrid (GridLayout):
Def__init__ (self, **kwargs):
Super (MyGrid, self).__init__ (**kwargs)
Self.cols=2
Self.add_widget (Label (text=”First Name :”))
Self.name=TextInput (multiline=False)
Self.add_widget (self.name)
Self.add_widget (Label (text=”last Name :”))
Self.name=TextInput (multiline=False)
Self.add_widget (self.lastname)
Self.add_widget (Label (text=”Email:”))
Self.name=TextInput (multiline=False)
Self.add_widget (self.email)

Example:-


kivy example

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India