     Python.  
 


     Python,  Kivy   KivyMD   ,       ( , , , -)      (Windows, Linux, MacOS, Android, iOS).          ,  ,             .





     Python

 



 



 ,2022



ISBN978-5-0056-1871-9

     Ridero







             [44].           ,    ,    .

 Digital 2020Reports [11],   We Are Social Inc. Hootsuite Inc.,       9 .  ,     -   800 ,    ,   . ,       .

      . ,  2024      . StatCounter [12],      45,66%.      .     ,  - .       .  ,        7 , ,        . ,  ,     ,   . Statista [33], 2019,      461. ., 2023    ,  ,   935. . .

      ࠖ Android iOS,   99%      .    , Android   ,    iOS,     25,75%.     Google Play Store      (2,5.), Apple App Store   1.8. .    ,  ,        .

 ,   ,         : Java  Kotlin  Android, Objective-C  Swift  iOS.     ,       . Ѡ ,         . Ѡ ,       ,      ,      ,  .

   ,    .    .  Microsift    Windows, Apple       Mac OS.     Linux.   Linux       .    Linux,  ,  -    .         ,       Linux.  ,  ,       ,      :  Windows,  Mac OS  Linux.          ,     .

     .    ,  ,    , iOS Android,  .      ,  React Native, Flutter, Ionic, Xamarin, PhoneGap.       ,    Windows, MacOS Linux.      ,  Electron JS, Qt, GTK, Avalonia, Tkinter.           ,   .     ,        ,  ,    ?       , .

  .

     ,  : Google, Apple Microsoft. Ӡ     ,    : Google  Android, Apple  Ios Macos, Micrisoft  Windows. Ƞ   ,   ,   ,  . Ƞ    .     :      ,  ,   ,  ,   ,    ,    .

 ,    ,     ,      Linux. Ƞ      .        ,    .

    . Ƞ , ,    ,     .         . Ƞ   ,  , ,     . Ƞ    ,  ,     , , ,  . Ƞ     .    Python,   Kivy.

Kivy  ,  2011,      .    Python,   .      Kivy     KivyMD.   MD  Material Design. Material Design   ,  Google,        Android iOS.

 Kivy  KivyMD    ,     ( , , , -)    (Windows, Linux, MacOS, Android, iOS, Raspberry Pi).     .  ,           .            ,    (, ,  ).

   ,   ,     Python, ,             .             ,     ,   .      ,    ,   ,        .     KV,      Python.    ,    Kivy.        KivyMD,           .

       ( ),    ,         Python.   ,        ,  ,    .    ,    ,      KV,    -  (, , , ).          ,   .   ,     .  ,       ,          .

      ,   ,     ,      .     Kivy  KivyMD,       .      ,   Python,      .

           (   ).    Python,     PyCharm, Kivy, KivyMD. ѠPyCharm    KivyKivyMD

    ,   Kivy.   KV  Kivy.   ,      ,   .    ,    .         Kivy.       .   Screen ScreenManager     .

       KivyMD     ,         (ScreenManager).        ,     

   KivyMD,      .    ,       .

        KivyMD.     .   ,      ,        .  , ,       ,    .

      Kivy KivyMD.     ,    ,    .

         Kivy Python.   APK-     Android      Linux,     ,       VirtualDox     Linux.    Buildozer,    APK-     Android       iOS.     .    pyinstaller         Windows MacOS (xOS).     .

       ,   .           .          ,        ,   ,     .        .     .     Python.         , ,        .

,        Python,KivyKivyMD,        .

     ,    ,     Python.  ,            ,            .

.



ʠ       ,     ,    .      ⠖ ,  ,     ,     .            ,       .            .       ,    .   ,        .      ,     .





 1.       Python



          .                 ,         ,    .      .          WhatsApp Viber, LinkedIn,   .

         ,    ,   .     ,  -,   ,   .

       ,        ,     Android,   iOS.      : Python,  Kivy  KivyMD.

Kivy   Python,     ,   Windows, Linux, Android, OSX, iOS    Raspberry Pi.        Python,        ,       .

 KivyMD    Kivy.    Material Design (MD)   Kivy.         ࠖ UI (user interface  ),      Kivy      , ,   ,    ,   , , GPS  ..

 Python Kivy     ,      :

  (OS X, Linux, Windows);

 iOS (iPad, iPhone);

Android- (, );

    ,  TUIO (Tangible User Interface Objects).

Kivy            .

                (IDE, Integrated Development Environment).      ,     Python.   IDE   ,   ,    .  IDE      (       ).     Python      IDE PyCharm    ,   Windows, macOS, Linux.

    :

   ;

     Python;

     PyCharm;

     Python    

   Kivy  KivyMD;

      Kivy KivyMD.




1.1.  


  (. Mobile app)   ,    ,    ,     (iOS, Android, Windows Phone . .).              .

 1520  ,    ,     .          ,    .   ,   堖           .       : , , , , - .         ,   App Store, Google Play    .

            ,    .      ,      -      .   ᠖              .        web-,        .

 堖   ,         .      :

          ;

        ;

    , -, ;

      ,    ;

     ,        ;

      (     , ,    ,      ..;

 ,  ,       ;

    (,  , ,  , Bluetooth  ..).

         .        , ,   ,   ,    .

       .    :

Java     ,     ,        Android;

Kotlin     ,     JAVA        Android;

Swift       iOS.    Swift      iOS;

Dart  , -  ,  ,      .   ,  Google,    JavaScript;

C #    - ,      .      Windows Mobile;

C ++ -       Android. ,      ,    Android;

Xamarin          ,     . NET C #. Xamarin    . NET,          iOS, Android Windows.

          (, Java  Android, Swift  iOS).    Python  Kivy KivyMD                 .




1.2.  Python


  Python         .          ,    ,        .        ,    ,    ,       .

   Python ,      .   Python   ,  : https://www.python.org/downloads/ (. 1.1).






. 1.1.       Python




1.2.1.  Python Windows


   Windows  Python      ( exe),     ( zip).        Python 3.8.3.

  Python Windows :

   .

   (. 1.2).






. 1.2.    Python



     : Install Now Customize installation:

  Install Now Python     .      IDLE (  ), pip ( ) ,       () ,   py,  Python;

Customize installation    .  Add Python 3.8toPATH   ,               .

   ,   . 1.3(    Customize installation).






. 1.3.    Python



     ,    Python.      :

Documentation  ;

pip   pip;

tcl/tk and IDLE     (IDLE)      (tkinter).

   Advanced Options ( )   ,   . 1.4(    Customize installation).






. 1.4.    Python



  ,          :

Install for all users    .    ,       ,  ;

Associate files with Python  ,   py, Python.        Windows,  Python     ;

Create shortcuts for installed applications     ;

Add Python toenvironment variables    Python  PATH;

Precomple standard library    .

       ,    .

   Python     (. 1.5).






. 1.5.     Python




1.2.2. Python Linux


   Python     Linux.   ,    :

> python



> python3

  ,   Python 2, 젖 Python 3.  ,  ,   Linux,  Python,      .      Python   ,     , ,   ,       .

  Python  Ubuntu  :

> sudo apt-get install python3




1.2.3.   Python


     .    Windows,     <Win> + <R>   : python.  Linux     : python3 ( python).

  Python   .     ,   . 1.6(   Windows, Linux   ).






. 1.6.    Python  



       :

print (Hello, World!)

      (. 1.7).






. 1.7.    Python  



   ,    Python   .




1.3.      PyCharm


          (IDE),  .  Python     IDE PyCharm  JetBrains.      : https://www.jetbrains.com/pycharm/download/ (. 1.8).






. 1.8.       PyCharm



     Windows, Linux macOS.     PyCharm: Professional Community.     Community,           .        PyCharm 2020.1.2.




1.3.1.  PyCharm Windows


    PyCharm (. 1.9).






. 1.9.     PyCharm



    (. 1.10).






. 1.10.    PyCharm



 ,      ( 32-  64-  PyCharm),   . py d  Create associations,    PyCharm   py (. 1.11).






. 1.11.      PyCharm



      (. 1.12).






. 1.12.     PyCharm 



 PyCharm     (. 1.13).






. 1.13.     PyCharm




1.3.2.  PyCharm Linux


      .

  ,     :

> tar xvf _. tar.gz

     . 1.14.






. 1.14.      PyCharm



 ,      ,    bin  .   PyCharm :

> ./pycharm.sh

     . 1.15.






. 1.15.     PyCharm




1.3.3.  PyCharm


 PyCharm   Create New Project   (. 1.16).






. 1.16.      PyCharm



    Python ,        (. 1.17).






. 1.17.      PyCharm



  ,      Python (. 1.18).






. 1.18.       Python



     (. 1.19).






. 1.19.     Python   PyCharm



   Run (. 1.20).






. 1.20.    Python   PyCharm



            (. 1.21).






. 1.21.     Python   PyCharm



   .




1.4.    Python   


     Python      (),      .

     ,           .  :

   ;

  pip   Python;

 pip;

  ;

  ;

  ;

    ;

    .




1.4.1.    PyPI


      ,         ,   Python. , ,  -,  ,  ,      ,  ..  ,  ,    ,   ,  , ,     .      ,     . ʠ        .

  Python     .    Python Package Index (PyPI) ,     Python,          .          ࠖ           Python.               .     Python    ,            .       .          ,   pip.  ,      ,         .    ,   ,   PyPI   pip.




1.4.2.   Pythonpip


  pip    (  ).  ,     ,   PATH    .       ,   Windows  Linux,    PyCharm :

> pip <>

pip     Python:

> python -m pip <>

 -m ,      (  pip).

    Python ( Python 2.7.9  ), pip  .  PyCharm    pip           File| Settings| Project Interpreter.  pip       (. 1.22).

. 1.22.    pip

          ,   +      pip  (. 1.23).

. 1.23.  pip




1.4.3.   pip


      pip:  ,   .

Pip      ,      ,    ,  , ,    .      . ,     ( Name   ).

   :

> pip installName

  :

> pip install Name==3.2

   3.1:

> pip install Name>=3.1

    ,  :

> pip uninstallName

     upgrade:

> pip install upgradeName

       :

> piplist

        ,    show:

> pip showName

         ,   ,     ,   search:

> pip search test.

   pip  Windows,       ,      .         .     ,  pip     /k. ,     tensorflow   ,   . 1.24.






. 1.24.    pip   Windows



  pip    PyCharm,      ,         .       PyCharm  . 1.25.






. 1.25.    pip   PyCharm




1.5.   Kivy  KivyMD


,       Python ,      ,         .       Kivy  KivyMD.

   PyCharm      Kivy_Project.        File| New Project (. 1.26).






. 1.26.      PyCharm



 ,       ,        ,    Python.         Kivy_Project,     Create (. 1.27).






. 1.27.     Kivy_Project   PyCharm



   . ,  ,  ,      (. 1.28).






. 1.28.  PyCharm   



        Kivy     Python,     ,    .        :   PyCharm,     pip   PyCharm.

   Kivy     File   Settings (. 1.29).






. 1.29.  Settings  



        Project Interpreter,           Python    (. 1.30).






. 1.30.    Python



   ,    "+"   ,        .         Kivy,        ,     (. 1.31).






. 1.31.   Kivy   



  Install Package,            (. 1.32).






. 1.32.  Kivy    



    KivyMD.    ,    "+"   ,        .         kivymd,        ,     (. 1.33).






. 1.33.   KivyMD   



  Install Package,         (. 1.34).






. 1.34.  KivyMD    



      (   pip)      PyCharm.    Kivy,  - pip install kivy (.1.35),   Enter.






. 1.35.   Kivy      PyCharm



,    KivyMD    PyCharm    pip install kivymd (.1.36),   Enter.






. 1.36.   KivyMD      PyCharm



         .

.



  ,          (         Python).        ,            ,    :

pip install kivy-deps.angle;

pip install kivy-deps.glew;

pip install kivy-deps.gstreamer;

pip install kivy-deps.sdl2.


      ,        Python. ,            .        .




1.6.   Kivy KivyMD


  Kivy   ,      .        Kivy_Project,      Python   First_App.               : New-> Python File (.1.37).






. 1.37.  Python   PyCharm



       First_App (.1.38)






. 1.38.   Python ,   PyCharm



 ,     Enter,      First_App.py (.1.39).






. 1.39. Python   First_App.py,   PyCharm



     First_App.py,     ( 1.1).



 1.1.     Kivy ( First_App.py)

import kivy. app #  kivy



class TestApp (kivy. app. App): #  

       

pass



app = TestApp () #   ( app) 

      

app.run () #  


      ,    Kivy (import kivy. app).        TestApp.    ,     .       kivy. app. App   app      . , ,     run      app.   .



.



  Python  ,         ,  C, C ++, Java,   ( ).     Python        .  IDE PyCharm  ()  ,       .           ,      .        .


    ,              Run First_App (.1.40).






. 1.40.     First_App.py  PyCharm



         (.1.41).






. 1.41.     First_App.py,   



        .        Kivy,    (Test)    ( ,  ,  ).       ,      :  ,   (),          App,         Test.        ,     .

  ,   ,   .      ,  ,     Windows Linux.        (, ),     ,       .

 ,         ,     Kivy KivyMD.

 ,       , ,  堖  Kivy.   Python      ( 1.2).



 1.2.     Kivy ( First_App_Kivy.py)

#  First_App_Kivy.py

import kivy. app #  kivy

import kivy.uix.label #    label ()



class MainApp (kivy. app. App): #  

            

 def build (self): #   

  return kivy.uix.label.Label (text= Kivy!)



app = MainApp (title=  Kivy) # 

           

app.run () #  


      :  (import kivy. app),    label  (import kivy.uix.label).     (MainApp)  ,  build.      (  ),      .          kivy.uix.label   Label,   (text),    Kivy.

        app  ,      (title=  Kivy). , ,     run     app.

       KivyMD ( 1.3).



 1.3.     KivyMD ( First_App_Kivy_MD.py)

#  First_App_Kivy_MD.py

from kivymd. app import MDApp

from kivymd.uix.label import MDLabel



class MainApp (MDApp):

def build (self):

  return MDLabel (text= KivyMD!, halign=center)



app = MainApp (title=  KivyMD)

app.run()


        .   ,      KivyMD (  ),         (halign=center).   KivyMD       .

      ,      (.1.42).






. 1.42.    Kivy KivyMD  



  ,         ( Kivy   ,  KivyMD ).

    ,        ,     ,   Kivy    ,  KivyMD    .        Kivy.       ,      Windows,    ,  Linux .          .          .

     ,     ,      .     Kivy     pyt. ico,  1.4.



 1.4.     Kivy ( First_App_Kivy2)

#  First_App_Kivy2.py

from kivy. app import App #   kivy

from kivy.uix.label import Label #   label ()



class MainApp (App): #   

 def build (self): #   

  self. title =  Kivy #  

  self. icon =. /pyt. ico #  () 

  label = Label (text= Kivy Python!) # 

 .return label #   



if __name__ == '__main__': #  

 app = MainApp () #  

 app.run () #  


         :  (import kivy. app)    label  (import kivy.uix.label).     (MainApp)   c  build.          self. title (,      )   .         Python  pyt. ico,     .          ࠖ self. icon =. /pyt. ico.           Kivy Python,  return    .       Python:

    (if __name__);

       (app = MainApp (title= );

  堖 app.run().

       KivyMD ( 1.5).



 1.5.     KivyMD ( First_App_KivyMD2.py)

#  First_App_KivyMD2.py

from kivymd. app import MDApp

from kivymd.uix.label import MDLabel



class MainApp (MDApp):

.def build (self):

  self. icon = 'icon.png

  self. title =  KivyMD

 label = MDLabel (text= KivyMD Python,

      halign=center)

  return label



if __name__ == '__main__:

 app = MainApp()

 app.run()


     ࠖ icon.png.

        (.1.43).






. 1.43.   Kivy KivyMD c  



   ,         .




 


       ,         Python,    ,    .   Python,      PyCharm,  Kivy  KivyMD.            ,   ,    .

         Kivy,    KV,   ,      .




 2.  Kivy,  KV ,    



     ,   ,    Kivy.   KV, 蠖 ,      .  ,    :

  Kivy    ;

    KV     ;

      ;

   ;

 ,      .

,      Kivy.




2.1.   Kivy


 Kivy     Python   . Ѡ        ( , , ).      ,   Kivy     .          ,      . Kivy    : Windows, OS X, Linux, Android, iOS, RaspberryPi.

     MIT (    ) 100%   .  Kivy     API.     OpenGLES2.

.



OpenGL ES2   ,      ( ,  ,  ).


     20,    .

.



       ,         .      .      ,   .       .


   Kivy          Python,       .        :  kivy KV, KV.        , KV.

 KV    :

     Kivy.

   (         );

   ;

      ;

  ,    .

 KV            .          .

      KV .

 .    Kivy   . kv  ,       ,   App. ,       MainApp,      KV     main. kv.     ,           .

Ѡ   () Builder       KV   ,    ,  . kv.          ,           .

Ӡ Builder        KV:

Builder. load_file (path/name_file. kv)    KV   ( path  , name_file. kv  );

Builder. load_string (kv_string)    KV    (kv_string   ).




2.2.  KV  







2.2.1.  


 ,   ,         .    ,    KV,     Kivy  KVlang.  KV      ,          .        .

 KV,  Python,  - .      ,     .     ,   ,      .   KV  :       (, Button , Label ),     (, text, text_size, font_size).

     KV     .    .    K_May_Class1.py     ( 2.1).



 2.1.     ( K_My_Class1.py)

#  K_May_Class1.py

from kivy. app importApp

from kivy.lang import Builder



KV=

BoxLayout: # (  BoxLayout)

Button: # ( Button)

  text:  1 #  ()





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


.



    Kivy,     :   Button (),   BoxLayout ().       .      .     蠖 ,          '''.


     KV       BoxLayout,    (Button),   text    1 ( KV       :).        ,   .       (.2.1).






. 2.1.     K_May_Class1.py



      젖  BoxLayout   .      .        .

   Python    ,      . ,     BoxLayout,      , , MyBox.    .    K_May_Class2.py     ( 2.2).



 2.2.     ( K_My_Class2.py)

#  K_May_Class2.py

from kivy. app importApp

from kivy.lang import Builder

from kivy.uix.boxlayout import BoxLayout



KV =

MyBox: # ( )

Button: # ( Button)

 text:  2 #  ( )





#   MyBox

#    BoxLayout

class MyBox (BoxLayout):

pass



class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


     Python    MyBox    BoxLayout.         BoxLayout:

from kivy.uix.boxlayout import BoxLayout

      (.2.2).






. 2.2.     K_May_Class2.py



           KV.     :

<__@__>

   .    K_May_Class3.py     ( 2.3).



 2.3.     ( K_My_Class3.py)

#  K_May_Class3.py

from kivy. app importApp

from kivy.lang import Builder



KV =

#   MyBox

#    BoxLayout

<MyBox@BoxLayout>



MyBox: # ( )

 Button: # ( Button)

  text:  3 #  ( )





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


      MyBox    BoxLayout    KV:

<MyBox@BoxLayout>

        BoxLayout,       Python.         .

.



   ,    ,    <>.


      (.2.3).






. 2.3.     K_May_Class3.py




2.2.2.  


  Kivy    .      ,          . ,  BoxLayout   ,     :



BoxLayout:

 Button:

  text: 1

  pos_hint: {center_x:.5, center_y:.6}

  font_size: 25sp

  markup:True

 Button:

  text: " 2

  pos_hint: {center_x:.5, center_y:.6}

  font_size: 25sp

  markup:True

 Button:

  text: " 3

  pos_hint: {center_x:.5, center_y:.6}

  font_size: 25sp

  markup:True


          ,           :



<MyButton@Button>:

 pos_hint: {center_x:.5, center_y:.6}

 font_size: 25sp

 markup:True



BoxLayout:

 MyButton:

  text: " 1

 MyButton:

  text: " 2

 MyButton:

  text: " 3


   ,    .    K_May_Class4.py     ( 2.4).



 2.4.     ( K_My_Class4.py)

#  K_May_Class4.py

from kivy. app importApp

from kivy.lang import Builder



KV =

<MyButton@Button>:

 font_size: 25sp

 pos_hint: {center_x:.5, center_y:.6}

 markup:True



BoxLayout:

 orientation: vertical

 MyButton:

  text: " 1

 MyButton:

  text: " 2

.. MyButton:

  text: " 3





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


       MyButton    Button.   MyButton     .   BoxLayout,    MyButton,       text.          MyButton@Button.  ,      .       (.2.4).






. 2.4.     K_May_Class3.py




2.2.3.    KV


  KV        . Python       =,     : name = value.  KV         :, , name: value.         , :



Button:

 text: 1


Python  ()     :



import numpy asnp


 KV    :



#:import np numpy


  KV     ,         :

app: ()     (,  KV   ,    ,  Python);

root: ()    ;

self: ()   ,   ()  ;

args ()      ;

ids ()       .

  self.   self  ࠫ  . Ѡ  , ,     .    .    Button_Self.py     ( 2.5).



 2.5.     self ( Button_Self.py)

#  Button_Stlf.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Button

 text:  蠖 %s% self.state





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


   text   : , , OK, ,  ..   text,   self    ࠖ   (self.state). ,      .       (.2.5).






. 2.5.     Button_State.py



   ,         .



  root.   root ()      .    .    Button_Root.py     ( 2.6).



 2.6.     root ( Button_Root.py)

#  Button_Root.py

from kivy. app importApp

from kivy.lang import Builder



KV =

BoxLayout:

 orientation: vertical

 Button:

 text: root. orientation





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    BoxLayout   orientation  堖 vertical.      Button ().   text,   root     ࠖ orientation (root. orientation). ,       .       (.2.6).






. 2.6.     Button_Root.py



   ,   ,      .



  app.      ,   .    ,    ,  Python.    .    Button_App.py     ( 2.7).



 2.7.     app ( Button_App.py)

#  Button_App.py

from kivy. app importApp

from kivy.lang import Builder



KV =

BoxLayout:

 orientation: vertical

 Button:

  text: 1

  on_press: app.press_button (self. text)

 Label:

  text: app.name





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



def press_button (self, instance):

 print (  !)

 print (instance)



MainApp().run()


.



     BoxLayout.          .


      BoxLayout.      ࠖ Button () Label ().    (on_press),    press_button.     Main,       app app.press_button (self. text).     ,     app   Main,   press_button,     text   (self. text).

 Label   text.     app    (Main).

,    app        ,  Label      Main.        (.2.7).






. 2.7.     Button_App.py



   ,  Label    (main),        text  蠖 1.

  args.             .   ,   .    .    Button_Args.py     ( 2.8).



 2.8.     args ( Button_Args.py)

#  Button_Args.py

from kivy. app importApp

from kivy.lang import Builder



KV =

BoxLayout:

 orientation: vertical

 Button:

  text: 1

  on_press: app.press_button (*args)

 TextInput:

  on_focus: self.insert_text ( if args [1] else )





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



 def press_button (self, instance):

  print (  !)

  print (instance)



MainApp().run()


      BoxLayout.      ࠖ Button () TextInput (   ).    (on_press),    press_button (*args).    ,      ( *  ,       ).

Ӡ TextInput     (on_focus).        insert_text ( ):

self.insert_text (" if args [1] else )

   ,   args [1].     ,       ,       ,     .        (.2.8).






. 2.8.     Button_Args.py



   ,     TextInput       ,        .          args.

  ids.   ids () id ()    . Ѡ   id       ().       ,      KV.

 :



Button:

 id:but1

 text: 1

Label:

 text: but1.text


      :  Button (),  Label ().     id    but1,        .  text  Label   but1.text.      bat1      text.       1.

   .    Button_Id.py     ( 2.9).



 2.9.     id ( Button_Id.py)

#  Button_Id.py

from kivy. app importApp

from kivy.lang import Builder



KV =

BoxLayout:

 orientation: vertical

 Button:

  id:bt1

  text: 1

  on_press: lb1.text = bt1.text

 Button:

  id:bt2

  text: 2

  on_press: lb1.text = bt2.text

 Label:

  id:lb1

  text: 

  on_touch_down: self. text = 





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


      BoxLayout.      :   Button,  Label.    bt1 蠫bt2,   lb1.    bt1 ( on_press)   text       bt2,   :



on_press: lb1.text = bt1.textxt


   bt2 ( on_press)   text       bt2,   :



on_press: lb1.text = bt2.text


   lb1 ( on_touch_down)   text    ,   :



on_touch_down: self. text = 


         .       (.2.9).






. 2.9.     Button_Id.py



   ,        Label,          .

Ѡ   ids   Python  ,      KV.    .    Button_Ids.py     ( 2.10).



 2.10.     ids ( Button_Ids.py)

#  Button_Ids.py

from kivy. app importApp

from kivy.lang import Builder

from kivy.uix.boxlayout import BoxLayout



KV =

box:

 Button:

  text: ' 

  on_press: root.result ( )

 Label:

  id:itog





class box (BoxLayout):

 def result (self, entry_text):

  self.ids [itog].text = entry_text



class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


  ,  Python,    box    BoxLayout.    ,   KV   :  Button  Label,    () itog.      (on_press).      root,  result,     .   def result     entry_text.         ids:



self.ids [itog].text = entry_text


   ,   text     () [itog]     entry_text.        ,     .       (.2.10).






. 2.10.     Button_Ids.py



   ,   ,      KV   Python,   .       ids id.

           KV Python,    .      Simpl_Calc.py     ( 2.11).



 2.11.     ids id ( Simpl_Calc.py)

#  Simpl_Calc.py

from kivy. app importApp

from kivy.lang import Builder

from kivy.uix.boxlayout import BoxLayout



KV =

box:

 # 

 id: root_widget

 orientation: vertical



 #    

 TextInput:

  id: entry

  font_size:32

  multiline: False



 #   

 Button:

  text:=

  font_size:64

  #on_press: root.result (entry. text)

  on_press: root_widget.result (entry. text)



 #    

 Label:

  id:itog

  text: 

  font_size:64





# ,   

class box (BoxLayout):

 #   

 def result (self, entry_text):

  if entry_text:

  try:

    #    

    result = str (eval (entry_text))

    self.ids [itog].text = result

   except Exception:

    #   

    self.ids [itog].text = 



#   

class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


       MainApp,    ,   box    BoxLayout ( ).      def result,   .    KV    :

  box (id: root_widget);

    TextInput (id: entry);

      (id: itog);

 Label     .

Ѡ -        KV Python.       (.2.11).






. 2.11.     Simpl_Calc.py



   , 蠖   .       KV,     Python.

       .   Kivy ,    :  ,   .       :

    ,      ;

    ,       .

       ,     (.2.12).






. 2.12.     Simpl_Calc.py  



   ,      .         ( ),   .     -    .     =  ,    .

   Kivy      Python.          .    .    Button_If.py     ( 2.12).



 2.12.    KV ( Button_If.py)

#  Button_If.py

from kivy. app importApp

from kivy.lang import Builder



KV =

BoxLayout:

 orientation: vertical

 Button:

  id:bt1

  text: 1

 Label:

  text:  if bt1.state == normal else 





class MainApp (App):

def build (self):

  return Builder. load_string(KV)



MainApp().run()


      BoxLayout.      :  Button,  Label.    id: bt1.   text  :



text:   if bt1.state == normal else  


   , ,      ,      .      ,      .       (.2.13).






. 2.13.     Button_If.py



,      KV, ,       KV  .        Kivy,    ,      .




2.3.   Kivy


     ,               .            .   ,      ,        . ʠ Kivy        KV.       ,            ,     (  ).            .      ,   ,     .

       Python KV:

  ;

 Builder.

     .




2.3.1.     


,      :    Python,     KV.      Python    ,      蠖 Class_nameApp.     KV     蠖 class_name. kv.      Class_nameApp . kv   ,    ,     APP. ,       My_ClassAPP,     KV    my_class. kv.     ,   ,    ,    .      ( 2.13).



 2.13.     (  ,  Soglashenie_Imen.py)

#  Soglashenie_Imen.py

from kivy. app import App #  ࠖ 



class Basic_Class (App): #  

pass



My_App = Basic_Class () #    

My_App.run () #  


       Basic_Class,       .     basic_class. kv     ( 2.14).



 2.14.  ,  basic_class.kv

#  basic_class.kv

Label:

 text:   basic_class.kv

 font_size: 16pt


      (Label),   (text)  堖   basic_class. kv,   ,       16pt.        (.2.14).






. 2.14.   Basic_Class    basic_class.kv



    ,    :

        (Basic_Class)   젖 basic_class.kv.

     ,       .

 , Kivy      ,   .    ,      堖  젖 basic_class. kv     ,       (    Soglashenie_Imen.py).




2.3.2.      Builder


  Builder,        :



from kivy.lang import builder


  Builder      KV       (. kv),      .

   . kv    :



Builder. load_file (. Kv/file/path)


          :



Builder. load_string (kv_string)


   .        KV   ,  Metod_Builder.py ( 2.15).



 2.15.   Builder (  KV  )  Metod_Builder.py

#  Metod_Builder.py

from kivy. app import App #  ࠖ 

from kivy.lang import Builder #   Builder



kv_file = Builder. load_file (. /basic_class.kv)



class Basic_Class (App): #  

 def build (self):

  return kv_file



My_App = Basic_Class () #    

My_App.run () #  


    kv_file ,   Builder. load_file,    . /basic_class. kv,     .      def build (self),     kv_file.     ,    .          basic_class. kv, ,    ,         .

,   .       ,  Metod_Builder2.py ( 2.16).



 2.16.   Builder Metod_Builder2.py (  KV  ,    ),  Metod_Builder2.py

#  Metod_Builder2.py

from kivy. app import App #  ࠖ 

from kivy.lang import Builder #   Builder



#   KV 

kv_file = Builder. load_file (. /KV_file/main_screen.kv)



class Basic_Class (App): #  

 def build (self):

  return kv_file



My_App = Basic_Class () #    

My_App.run () #  


    kv_file ,   Builder. load_file,     main_screen. kv,     KV_file.     KV_file,      main_screen. kv      ( 2.17).



 2.17.   ( main_screen.kv)

#  main_screen.kv

Label:

 text: ( ./KV_file/main_screen.kv)

 font_size: 16pt


        (.2.15).






. 2.15.   Basic_Class    main_screen.kv



 , Kivy           .    ,    KV (< >.kv)        .

  ,         ,    .  ,        KV       ( 2.18).



 2.18.   Builder (  KV  )  Metod_Builder1.py

#  Metod_Builder1.py

from kivy. app import App #  ࠖ 

from kivy.lang import Builder #   Builder



#   

my_str =

Label:

 text: (   )

 font_size: 16pt





#    

kv_str = Builder. load_string (my_str)



class Basic_Class (App): #  

 def build (self):

  return kv_str



My_App = Basic_Class () #    

My_App.run () #  


     my_str      KV.   kv_str   Builder. load_string,     my_str.      def build (self),     kv_str.      .2.16.






. 2.16.   Basic_Class     



 , Kivy           ,      .

,    ,  Kivy      ()  KV,  ,    ,     .  ,        ,    ,  ,    .     Kivy,         ,   .




2.4.  Kivy


   Kivy   .  Kivy    .

UX-,    (   ,   );

    (          );

 UX- (  ,    );

  (,       );

  ( ,     ).

       .      ,  ,  ..        .        .  Kivy  KivyMD    .

   Kivy   . ,       ,   (,   )    .           ,   ,    .        ,      .  ,            .         Kivy.




2.5.    (UX-)


Ӡ Kivy     :

Label    (   );

Button ;

Checkbox ;

Image ;

Slider ;

ProgressBar ;

TextInput    ;

ToggleButton  ;

Switch ;

Video     ;

Widget   ().

  ,    ,      Kivy.

.



       KivyMD. Π     .





2.5.1.  Label 


 Label      .       ascii,   unicode.   ,     Label .      K_Label_1.py     ( 2.19).



 2.19.    Label ( K_Label_1.py)

#  K_Label_1.py

from kivy. app importApp

from kivy.uix.label import Label



class MainApp (App):

 def build (self):

  L = Label (text= , font_size=50)

  returnL



MainApp().run()


     - L    Label.    text  ,      ,  font_size    -50.        (.2.17).






. 2.17.     K_Label_1.py



    Label     Python.      KV.      K_Label_2.py     ( 2.20).



 2.20.    Label ( K_Label_2.py)

#  K_Label_2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Label:

 text:  

 font_size:50





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    Label     KV,     ,    .

 Label   ,       :

text ,     (  ,   ..);

font_size  ;

color  ;

font_name     (.ttf).




2.5.2.  Button 


 Button   ,       .  Button   ,   Label.   ,     Button .      K_Button_1.py     ( 2.21).



 2.21.    Button ( K_Button_1.py)

#  K_Button_1.py

from kivy. app importApp

from kivy. uix. button import Button



class MainApp (App):

 def build (self):

  btn = Button (text= , font_size=50)

  returnbtn



MainApp().run()


     - btn    Button.    text  ,      ,  font_size    -50.        (.2.18).






. 2.18.     K_Button _1.py



    Button     Python.    ,        .      ,      ,     ,   .       KV.      K_Button_2.py     ( 2.22).



 2.22.    Button ( K_Button _2.py)

#  K_Button_2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Button:

 text:  

 font_size:50





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    Button     KV,     ,    .

 Button   ,     ,  ,      :

text  ;

font_size  ;

color  ;

font_name     (.ttf).

on_press , ,   ;

on_release , ,   ;

on_state  ( ,     ).




2.5.3.  CheckBox 


 CheckBox ()    -  .      ,  .   ,     CheckBox .      K_CheckBox_1.py     ( 2.23).



 2.23.    CheckBox ( K_CheckBox_1.py)

#  K_CheckBox_1.py

from kivy. app importApp

from kivy.uix.checkbox import CheckBox



class MainApp (App):

 def build (self):

  checkbox = CheckBox()

  return checkbox



MainApp().run()


     - checkbox    CheckBox.        (.2.19).






. 2.19.     K_CheckBox _1.py



    CheckBox     Python.    ,         .      ,       ,     ,   .       KV.      K_CheckBox_2.py     ( 2.24).



 2.24.    CheckBox ( K_CheckBox _2.py)

#  K_CheckBox_2.py

from kivy. app importApp

from kivy.lang import Builder

KV =

CheckBox:





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    CheckBox     KV,     ,    .

 CheckBox   ,        :

color   ( r, g,b,a);

active     (True   , False   ).




2.5.4.  Image 


 Image ()      .   ,     Image .      K_Image_1.py     ( 2.25).



 2.25.    Image ( K_Image_1.py)

#  K_ Image _1.py

from kivy. app importApp

from kivy.uix.image import Image



class MainApp (App):

 def build (self):

  img = Image(source="./Images/Fon2.jpg)

  returnimg



MainApp().run()


     - img    Image.    source    .        (.2.20).






. 2.20.     K_Image _1.py



    Image     Python.       KV.      K_Image_2.py     ( 2.26).



 2.26.    Image ( K_ mage_2.py)

#  K_Image_2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Image:

 source: "./Images/Fon2.jpg





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    Image     KV,     ,    .

 Image  ,       :

source  (    );

color   ( r, g, b, a),     .

    AsyncImage,      (,  -).    ,       (   ).




2.5.5.  Slider  ()


 Slider ()  ,         .   ,     Slider .      K_Slider_1.py     ( 2.27).



 2.27.    Slider ( K_Slider_1.py)

#  K_Slider_1.py

from kivy. app importApp

from kivy.uix.slider import Slider



class MainApp (App):

 def build (self):

  slide = Slider (orientation=vertical,

  value_track=True,

  value_track_color= (1, 0, 0,1))

  return slide



MainApp().run()


     - slide    Slider.     :

orientation=vertical  ;

value_track=True   ;

value_track_color= (1, 0, 0, 1)     ().

       (.2.21).






. 2.21.     K_Slider_1.py (   )



    Slider     Python.       KV.      K_Slider_2.py     ( 2.28).



 2.28.    Slider ( K_Slider_2.py)

#  K_Slider_2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Slider:

 orientation: horizontal

 value_track:True

 value_track_color: 1, 0, 0,1





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    Slider     KV,     .       .        (.2.22).






. 2.22.     K_Slider_2.py (   )



 Slider   ,     ,      :

min   (𠖠0);

max   ( 500);

value  ()  (𠖠50);

step    (𠖠1);

value_track_color    ( r, g, b,a);

value_track    (True , False)

orientation   (vertical , horizontal );

on_touch_down  ( );

on_touch_up  ( );

on_touch_move  (  ).




2.5.6.  ProgressBar 


 ProgressBar ()       .   ,     ProgressBar .      K_ProgressBar_1.py     ( 2.29).



 2.29.    ProgressBar ( K_ProgressBar_1.py)

#  K_ProgressBar_1,py

from kivy. app importApp

from kivy.uix.progressbar import ProgressBar



class MainApp (App):

 def build (self):

  Progress = ProgressBar (max=1000)

  Progress.value =650

  return Progress



MainApp().run()


     - Progress    ProgressBar.     :

max=1000    ;

value = 650    .

       (.2.23).






. 2.23.     ProgressBar _2.py



    ProgressBar     Python.       KV.      K_ProgressBar_2.py     ( 2.30).



 2.30.    ProgressBar ( K_ProgressBar_2.py)

#  K_ProgressBar_2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

ProgressBar:

 max:1000

 value:650





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    ProgressBar     KV,     ,    .

 ProgressBar   ,      :

max  ;

value  ;




2.5.7.  TextInput    


 TextInpu ( )     .   ,     TextInput .      K_TextInput_1.py     ( 2.31).



 2.31.    TextInput ( K_TextInput_1.py)

#  K_TextInput_1.py

from kivy. app importApp

from kivy. uix. textinput import TextInput



class MainApp (App):

 def build (self):

  my_text = TextInput (font_size=30)

  return my_text



MainApp().run()


      my_text        TextInput.   font_size=30  .        (.2.24).






. 2.24.     K_TextInput_1.py



    TextInput     Python.       KV.      K_TextInput_2.py     ( 2.31).



 2.31.    TextInput ( K_TextInput_2.py)

#  K_TextInput_2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

 TextInput:

 font_size:30





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    TextInput     KV,     ,    .

 TextInput   ,       :

text  (   .);

font_size  ;

color  ;

font_name     (.ttf);

password    (   True);

password_mask   (,    ).




2.5.8.  ToggleButton  


 ToggleButton     .    ,     ,       .   ,     ToggleButton .      K_ToggleButton_1.py     ( 2.33).



 2.33.    ToggleButton ( K_ToggleButton_1.py)

#  K_ToggleButton_1.py

from kivy. app importApp

from kivy.uix.togglebutton import ToggleButton



class MainApp (App):

 def build (self):

  t_but = ToggleButton (text=,

  font_size=50)

  return t_but



MainApp().run()


      t_but       ToggleButton.  text       font_size=50.        (.2.25).






. 2.25.     K_ToggleButton_1.py



    ToggleButton     Python.       KV.      K_ToggleButton_2.py     ( 2.34).



 2.34.    ToggleButton ( K_ToggleButton_2.py)

#  K_ToggleButton_2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

ToggleButton:

 text: 

 font_size:50





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    ToggleButton     KV,     ,    .

 ToggleButton       .          ⠫ .       .      K_ToggleButton_3.py     ( 2.35).



 2.35.    ToggleButton  ( K_ToggleButton_3.py)

#  K_ToggleButton_3.py

from kivy. app importApp

from kivy.lang import Builder



KV =

BoxLayout:

 orientation: vertical

 ToggleButton:

  text: 

  group:city

  state: down

 ToggleButton:

  text: 

  group: city

 ToggleButton:

  text: 

  group: city





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    3,     city.     堖 state: down.       (.2.26).






. 2.26.     K_ToggleButton_3.py



   ,        .

 ToggleButton   ,     ,  ,      :

text  ;

font_size  ;

color  ;

font_name     (.ttf).

on_press , ,   ;

on_release , ,   ;

on_state  ( ,     );

group    ( ,  city);

state    (down ).




2.5.9.  Switch 


 Switch   ࠖ .     ,   ,  .  Switch     (on)  (off).    ,     .   ,     Switch .      K_Switch1.py     ( 2.36).



 2.36.    Switch ( K_Switch_1.py)

#  K_Switch1.py

from kivy. app importApp

from kivy. uix. switch import Switch



class MainApp (App):

 def build (self):

  sw = Switch (active=True)

  returnsw



MainApp().run()


      sw ( )    Switch.  active ()   True ().        (.2.27).






. 2.27.     K_Switch1.py



    Switch     Python.       KV.      K_ Switch_2.py     ( 2.36_1).



 2.36_1.    Switch ( K_Switch_1.py)



#  K_Switch2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Switch:

 active:True





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    Switch     KV,     ,    .

      83x32 .  Switch   ,      :

active   (   False)

on_touch_down  ( );

on_touch_up  ( );

on_touch_move  (  ).

ʠ,     text,          Label.




2.5.10.  Video    


 Video         .  Video   play (),     : True  , False  .

.



           . ,   pygame    MPEG1 Linux OSX, GStreamer      ,   MKV, OGV, AVI, MOV, FLV (    gstreamer).


  ,     Video .      K_Video1.py     ( 2.37).



 2.37.    Video ( K_Video_1.py)

#  K_Video1.py

from kivy. app importApp

from kivy.uix.video import Video



class MainApp (App):

 def build (self):

  video = Video(source="./Video/My_video.mp4, play=True)

  return video



MainApp().run()


      video (   )    Video.  play ()   True ().        (.2.28).






. 2.28.     K_Video1.py



.



    , ,     -   .            ffpyplayer.     Pycharm  : pip install ffpyplayer


    video     Python.       KV.      K_Video_2.py     ( 2.37_1).



 2.37_1.    Video ( K_Video_2.py)

#  K_Video2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Video:

 source: "./Video/My_video.mp4

  play:True





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    Video     KV,     ,    .

 Video   ,      :

source  (    )

play  ( False,     -True);

state  (  : play , pause  , stop );

volume  ,   01(1  , 0  ).




2.5.11.  Widget   ( )


Widget    ,     ,     .   ,      GUI Kivy.  ,        .

  ,     Widget .      K_Widget_1.py     ( 2.38).



 2.38.    Widget ( K_Widget_1.py)

#  K_Widget_1.py

from kivy. app importApp

from kivy. uix. widget import Widget



class MainApp (App):

 def build (self):

  wid = Widget()

  returnwid



MainApp().run()


      wid ( )    Widget.        (.2.29).






. 2.29.     K_ Widget _1.py



   ,  Widget   .     wid     Python.       KV.      K_Widget_2.py     ( 2.39).



 2.39.    Widget ( K_Widget_2.py)

#  K_Widget_2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Widget:





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


    Widget     KV,     ,    .

Ӡ     canvas,      .       .  ,       : Color () Rectangle (, ). Ѡ        ,    .

       K_Widget_3.py     ( 2.40).



 2.40.    Widget ( K_Widget_3.py)

#  K_Widget_3.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Widget:

 canvas:

  Color:

   rgba: 0, 1, 0,1

  Rectangle:

   pos: self.pos

   size: self.size





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


      Widget,   canvas    :

Color ()  (rgba: 0, 1, 0,1);

Rectangle ()    ,   .

       (.2.30).






. 2.30.     K_ Widget _3.py



   ,     .     ,    ,     .

    .        K_Widget_4.py     ( 2.41).



 2.41.    Widget ( K_Widget_4.py)

#  K_Widget_4.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Widget:

 canvas:

  #Color:

  #rgba: 1, 0, 0,1

 Rectangle:

  source: './Images/Fon.jpg

  pos: self.pos

  size: self.size





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


      Widget,   canvas  Rectangle ()    './Images/Fon.jpg.  Color () ,      .     ,     .        (.2.31).






. 2.31.     K_Widget _4.py



   ,   color   .

 Widget   ,      :

canvas  ,   (   );

Color      (   );

rgba  ( ),   r, g, b,a;

Rectangle       (   );

source  (   ,    );

size  ( self.size,   ,   );

pos  ( self. pos,   ,   ).



,        Kivy.   ,  ,      ,   Python,   Python  KV.          KV,       .  ,               ,    .      Layout (, , ).     ,   ,      .      .      蠖 ,      .




2.6.    Kivy







2.6.1.      


 Kivy        .      ,  ,         .

   Button,          .    Button1.py     ( 2.42).



 2.42.    Button   ( Button1.py)

#  Button1.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Button:

 text:  

 size_hint:.5,.5

 #    

 #size_hint:.8,.5

 #size_hint:.5,.8



 pos_hint: {center_x:.5, center_y:.5}

 #          

 #size_hint:.2,.1

 #pos_hint: {center_x:.15, center_y:.5}

 #pos_hint: {center_x:.85, center_y:.5}

 #pos_hint: {center_x:.5, center_y:.15}

 #pos_hint: {center_x:.5, center_y:.85}





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


   KV   Button ().      :

text  

size_hint  ;

pos_hint    .

     ( text    ).           (size_hint pos_hint).   .

     (    #):

size_hint:.5,.5;

pos_hint: {center_x:.5, center_y:.5}.

  size_hint     (ࠖ x)  ( -y).  ,  .       1( 100%),        0.5( 50%)    .

  pos_hint     ,  ,  . ,       1( 100%),         ,  0.5( 50%)    ( x), 0.5( 50%)    ( y).

       (.2.32).






. 2.32.   Button1.py  



   ,       .     {center_x:.5, center_y:.5},   {x:.5, y:.5}.

   Button1_1.py     ( 2.43).



 2.43.    Button   ( Button1_1.py)

#  Button1_1.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Button:

 text:  

 size_hint:.5,.5

 pos_hint: {x:.5, y:.5}





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


       (.2.33).






. 2.33.   Button1_1.py  (    )



 Kivy  ,    ?       ,         .          .  ,       .     , ,  . ,        ,           .

   .    ,       size_hint ( ):



#size_hint:.8,.5

#size_hint:.5,.8


     蠖 0.8,    蠖 0.8.  ,     .     . 2.34.






. 2.34.   Button1.py     



,   (Button)  ,  Kivy       .

         .      pos_hint.

  ,  KV   (x, y)      .    (size_hint:.2,.1)      ,        :



#size_hint:.2,.1

#pos_hint: {center_x:.15, center_y:.5}

#pos_hint: {center_x:.85, center_y:.5}

#pos_hint: {center_x:.5, center_y:.15}

#pos_hint: {center_x:.5, center_y:.85}


   ,     ,   (.2.35):






. 2.35.      



  Kivy     ,   .     :

size_hint: None, None      (    );

size    , , 150, 50(150  , 50  );

pos      , , 140, 40(140   x, 40  y).

   Button,          .    Button2.py     ( 2.44).



 2.44.     Button   ( Button2.py)

#  Button2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Button:

text: 

 size_hint: None,None

 size: 150,50

 pos: 100,50





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


      Button     ࠖ 150, ࠖ 50,      (x= 100, y=50).  ,  size_hint: None, None        .

.



  Kivy     (x=0, y=0)    .


      (.2.36).






. 2.36.           



,       Kivy   ࠖ         .

 , ,        :

text  ;

size_hint    (, size_hint:.5,.5);

pos_hint      (, ࠖ pos_hint: {center_x:.5, center_y:.5}    ࠖ pos_hint: {x:.5, y:.5}).

size_hint: None, None      (    );

size    , , size: 150, 50(150  , 50  );

pos      , , pos: 140, 40(140   x, 40  y).




2.6.2.   


    ,      .  Kivy   background_color.      ,       .

   ,    ,    .     RGB (, , )       01(, background_color:1,0,0,1  , 0,1,0,1  , 0,0,1,1  ).

      ,        01,       . ,  ,      . ʠ         ,     ,  01,       .

     .   Button_Color.py      ( 2.45).



 2.45.      background_color ( Button_Color.py)

#  Button_Color.py

from kivy. app importApp

from kivy.lang import Builder



KV =

GridLayout:

 cols:3

 rows:2



 Button:

  text: 

  background_color: 1, 0, 0,1

 Button:

  text: 

  background_color: 0, 1, 0,1

 Button:

  text: 

  background_color: 0, 0, 1,1

 Button:

  text: 

  background_color: 0, 0, 0,1

 Button:

  text: 

  color: 0,0,0,1

  background_normal:

 Button:

  text: 

  background_color: 102/255, 255/255, 255/255,1





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


       ,   6.     .

.



 ,          background_normal:.


       ,   ,    ,     (color: 0,0,0,1).        102/255, 255/255, 255/255, 1.  ,    RGB     102, 255, 255.    Kivy          255.

    ()     1. , ,    ( )    (    .png   ).       0100% ( 01).   1    ( ), 0   ( ),    01( )        ().       1.     Kivy,         .

     . 2.37.






. 2.37.      background_color



,          background_color: r, g, b, a(, background_color: 1, 0, 0,1).




2.6.3.   


       , Kivy  . Ѡ       ,       .  Kivy   (Clock),          .

 Kivy     :

     ;

     .

   .           Button_Otklik1.py     ( 2.46).



 2.46.         ( Button_Otklik1.py)

#  Button_Otklik1.py

from kivy. app importApp

from kivy. uix. button import Button



class MainApp (App):

 def build (self):

  button = Button (text=,

    size_hint= (.5,.5),

    pos_hint= {center_x:.5, center_y:.5})

  button.bind(on_press=self.press_button)

  return button



 def press_button (self, instance):

  print (  !)



MainApp().run()


      :

 (def build)   ,          (on_press) 頖 press_button;

  (def press_button)   ,       (          !).

        (.2.38).






. 2.38.   ,   



  ,      ( ),     堖   ! (.2.39).






. 2.39.       



        Python.       KV.      Button_Otklik11.py     ( 2.47).

 2.47.         ( Button_Otklik11.py)



#  Button_Otklik11.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Button:

 text: 

 size_hint:.5,.5

 pos_hint: {center_x:.5, center_y:.5}

 on_press: app.press_button (root)





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



 def press_button (self, instance):

  print (  !)



MainApp().run()


   KV     (on_press).         press_button,     (root).     ,     .

 Kivy     :



:   


,    堖 on_press ( ).        KV,     :



Button:

 on_press: print ( )


     ,  Python,    :



#   KV

Button:

on_press: app.press_button (args)



#   Python

def press_button (self):

print (  !)


          Button_Otklik2.py     ( 2.48).



 2.48.         ( Button_Otklik2.py)

#  Button_Otklik2.py

from kivy. app importApp

from kivy. uix. button import Button



class Basic_Class1 (App):

 def build (self):

  button = Button (text=,

   .. size_hint= (.5,.5),

   .. pos_hint= {center_x:.5, center_y:.5})

 return button



 def press_button (self):

  print (  !)



My_App = Basic_Class1 () #    

My_App.run () #  


     button    Button,         ,    press_button .

Ѡ      ,   button     .       KV. ,      Kivy     ,    (  렖 basic_class1.kv),    .    ( )   basic_class1.kv      ( 2.49).



 2.49.   basic_class1.kv ( basic_class1.kv)

#  basic_class1.kv

<Button>:

 on_press: app.press_button()


         ,    KV.     ,     ,    .




2.7.  ⠖    


  Kivy      .      .2.40.






. 2.40.   



     . , , ,    ,   .   ,  堖     (  1 蠫  2).   ,       .     1,   ,     1.1.      .      .     ,     .      ,    ( ,    ,   ).          KV,   Python.

          ,   .    ,       Kivy.    Kivy,     ,    :

     (   );

     (      ).

       : , ,  ,  Layout.

     KV          .         .        4      . :



 :

  1:

   1.1:

  2:

   2.1:

     2.1.1:

     2.1.2:


          Tab.

 Kivy   .        ,     .        KV,  Python.

 Python       :

add_widget ():      ;

remove_widget ():     ;

clear_widgets ():      .

,      BoxLayout,       :



layout = BoxLayout (padding=10) #  

button = Button (text=) #  

layout.add_widget (button) #   


       K_Treet_1.py     ( 2.50).



 2.50.     Python ( K_Tree_1.py)

#  K_Tree_1.py

from kivy. app importApp

from kivy.uix.boxlayout import BoxLayout

from kivy. uix. button import Button

from kivy.uix.screenmanager import Screen



class MainApp (App):

 def build (self):

  scr = Screen () #   ()

  box = BoxLayout () # box

  but1 = Button (text= 1) # 1

  but2 = Button (text= 2) # 2

  box.add_widget (but1) #   1

  box.add_widget (but2) #   2

  scr.add_widget (box) #    

 returnscr



MainApp().run()


       scr ()    Screen.    box    BoxLayout.      but1 but2    Button.      ,     .        (.2.41).






. 2.41.     K_Treet_1.py



    ,          .

   KV     :



Screen: #   ()

 BoxLayout: #  BoxLayout

 Button: #   Button ()

 Button: #   Button ()


      K_Treet_2.py     ( 2.51).



 2.51.     Python ( K_Tree_2.py)

#  K_Tree_2.py

from kivy. app importApp

from kivy.lang import Builder



KV =

Screen: #   ()

BoxLayout: #  BoxLayout

  Button: #   Button ()

   text: 1

  Button: #   Button ()

   text: 2





class MainApp (App):

 def build (self):

  return Builder. load_string(KV)



MainApp().run()


      ,   .      ,          (  ).

   Python        . ,       :



but1 = Button (text=1)


   KV  :



Button:

 text: 1


.



 KV      ,  ⠖  .


     蠖 ,       ,     .




2.8.       Kivy


 Kivy     layout ,   .    ,       .      .

AnchorLayout.   ,     .          (  size_hint).

BoxLayout.      (  ),     ,      .    size_hint ( )     ,     ,        .

FloatLayout.        (   ,    ).

GridLayout.    Grid (, ).       (   ),  kivy      .

PageLayout.             .

RelativeLayout.   ,  FloatLayout,  ,        , .

Scatter.     . ,     ,       .     ,  ,   .

ScatterLayoyt.     . ,     ,       .     ,  ,      .

StackLayout.      ,     ,       .          .




  .


   .

   ,     (https://www.litres.ru/pages/biblio_book/?art=67257131)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


