计算输入的多个结果并替换标签KIVY

时间:2018-05-21 11:42:50

标签: python kivy kivy-language

获取宽度,长度和价格以及计算结果的应用

在这里我有3个条目和一个按钮,它将点击要计算的信息而不是标签

例如:
1 - > Input1,Input2,Input3都在float中 2 - >按按钮进行计算我有多个答案和多个标签 如何设置标签中的结果

App ui in graphical test (real verison in debug mode on andriod) Main.py ```

import kivy
kivy.require('1.0.7')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty
from kivy.uix.textinput import TextInput

class root(BoxLayout):

    def __init__(self, **kwargs):
        super(root, self).__init__(**kwargs)


    def cal(self):
        print(int(self.ertefa.input_text))
        pass

class HeroApp(App):
    kv_directory = 'template1'

    def build(self):
        return root()

if __name__ == '__main__':
    HeroApp().run()

<小时/> kv文件:

#:kivy 1.0
<root>:
    BoxLayout:
        orientation:'vertical'

        Image:
            source:'top.png'
            allow_stretch: True
            size_hint: 1 , None
    # -------------------------------------------
        GridLayout:
            id:'inputs"
            rows:3
            col:2
            size_hint: 1, .4
            padding : 5


    # INPUT ---[ ERTEFA ASLI ]---------------------------

            TextInput:
                id: ertefaa
                input_filter : 'float'
                multiline: False
                font_size: 42
                text: ''

            Image:
                source:'img1.png'

    # INPUT ---[ ARZ ASLI ]------------------------------

            TextInput:
                id: arzz
                input_filter : 'float'
            Image:
                source:'img2.png'

    # INPUT ---[ GHEYMAT ]--------------------------------

            TextInput:
                id: gheymatt
                input_filter : 'float'
            Image:
                source:'img3.png'

    # PROC --[ Def Button ]------------------------------

        Button:
            size_hint: 1, .15
            text: 'TURSAN CALLCULATE'
            on_press : ertefaa - 6


    # ----------------------------------------------------
        GridLayout:
            id: 'outputs'
            rows:9
            col:2
            padding : 5


    # OUTPUT ---[ ERTEFA FRAME ]--------------------------

            Label:
                id : ertefaframe
                text: '213'
                color:[10,1,255,1]
                font_size : 26
            Image:
                source:'out1.png'


    # OUTPUT ---[ ARZ FRAME ]--------------------------

            Label:
                id : arzframe
                text: '213'
                font_size : 26
            Image:
                source:'out2.png'


    # OUTPUT ---[ MOTAHAREK ]--------------------------
            Label:
                id : motaharek
                text: '213'
                font_size : 26
            Image:
                source:'out3.png'


    # OUTPUT ---[ ERTEFA TUR ]------------------------
            Label:
                id : erteftur
                text: '213'
                font_size : 26
            Image:
                source:'out4.png'


    # OUTPUT ---[ GAM TUR ]---------------------------

            Label:
                id : gamtur
                text: '213'
                font_size : 26
            Image:
                source:'out5.png'

    # OUTPUT ---[ METRE MORABA ]------------------------
            Label:
                id : metr
                text: '213'
                font_size : 26
            Image:
                source:'out6.png'

    # OUTPUT ---[ GHEYMAT KOLL ]------------------------
            Label:
                id: gheymatkoll
                text: '213'
                font_size : 26
            Image:
                source:'out7.png'

    # INFO ---[ ADDRESS ]------------------------
        Image:
            source:'down.png'
            size_hint: 1, None

1 个答案:

答案 0 :(得分:0)

来自kivy documentation

  

文字

     

标签文字。

     

创建一个简单的hello世界:

     

widget = Label(text='Hello world')

     

如果要使用unicode字符串创建窗口小部件,请使用:

     

widget = Label(text=u'My unicode string')

     

text是 StringProperty ,默认为''。

如果要更改特定标签的文本,只需使用其ID进行检索,然后设置所需的文本:

self.ids.id_of_label_you_want_to_change.text = "Text you want to set"