Chapter 1: Getting started with kivy


Example 8: the button prints the label's text (with a def in python using



Download 0,86 Mb.
Pdf ko'rish
bet10/15
Sana01.01.2022
Hajmi0,86 Mb.
#285987
1   ...   7   8   9   10   11   12   13   14   15
Bog'liq
kivy

Example 8: the button prints the label's text (with a def in python using 

ids

(the "IDs") )

Notice that:

self_xx

 from example 7 is replaced by 

self



In .py:



from kivy.app import App 

from kivy.uix.boxlayout import BoxLayout 

 

class MyLayout(BoxLayout): 



    def printMe(self): 

        print(self.ids.mylabel.text) 

class TutorialApp(App): 

    def build(self): 

        self.load_kv('myapp.kv') 

        return MyLayout() 

TutorialApp().run()

In myapp.kv:



 

    orientation:"vertical" 

    Label: 

        id:mylabel 

        text:"My App" 

    Button: 

        text: "Click me!" 

        on_press: root.printMe()



Example 9: the button prints the label's text (with a def in python using StringProperty)

In .py:


from kivy.app import App 

from kivy.uix.boxlayout import BoxLayout 

from kivy.properties import StringProperty 

class MyLayout(BoxLayout): 

    stringProperty_mylabel= StringProperty("My App") 

    def printMe(self): 

        print(self.stringProperty_mylabel) 

 

class TutorialApp(App): 



    def build(self): 

https://riptutorial.com/

11



        return MyLayout() 

TutorialApp().run()

In Tutorial.kv:

 

    orientation:"vertical" 

    Label: 

        id:mylabel 

        text:root.stringProperty_mylabel 

    Button: 

        text: "Click me!" 

        on_press: root.printMe()



Example 10: the button prints the label's text (with a def in python using ObjectProperty)

In .py:


from kivy.app import App 

from kivy.uix.boxlayout import BoxLayout 

from kivy.properties import ObjectProperty 

class MyLayout(BoxLayout): 

    objectProperty_mylabel= ObjectProperty(None) 

    def printMe(self): 

        print(self.objectProperty_mylabel.text) 

 

class TutorialApp(App): 



    def build(self): 

        return MyLayout() 

TutorialApp().run()

In Tutorial.kv:



 

    orientation:"vertical" 

    objectProperty_mylabel:mylabel 

    Label: 

        id:mylabel 

        text:"My App" 

    Button: 

        text: "Click me!" 

        on_press: root.printMe()

Read Getting started with kivy online: 

https://riptutorial.com/kivy/topic/2101/getting-started-with-

kivy


https://riptutorial.com/

12




Download 0,86 Mb.

Do'stlaringiz bilan baham:
1   ...   7   8   9   10   11   12   13   14   15




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish