【问题标题】:it's possible how we can put value in kivy file and return value to py file.and deal with it我们可以如何将值放入 kivy 文件并将值返回给 py 文件并处理它
【发布时间】:2021-01-22 02:21:34
【问题描述】:

我将编写简单的代码以更好地理解,假设我们在 kivy 文件中有 3 个按钮,如下面的代码

kivy 文件:

Button:
   text: A1
   variable = 3
Button:
   text : A2
   variable = 2
Button:
   text :A3
   variable = 3

当我在每个按钮上按下变量根据我们定义的值改变时,如何将变量放入 kivy 文件中,然后在 python 文件中处理变量

py 文件

def btn(self):
    new_variable= variable+5

【问题讨论】:

    标签: python python-3.x kivy kivy-language kivymd


    【解决方案1】:

    您可以使用文本输入:

    基维

    Label:
       id:label
       text:'here is displayed the final result'
    
    #here you insert content of variable
    TextInput:
        id: txt_inpt
        text: '' 
        font_size:16
    
    Button:
        text: 'A1'
        on_press: root.func()
    

    Python:

    def func():
        var= self.ids.txt_inpt.text
        addvar = int(var) + 5
        self.ids.label.text = str(addvar)
    

    【讨论】:

      猜你喜欢
      • 2021-02-16
      • 1970-01-01
      • 2011-04-19
      • 2015-05-15
      • 1970-01-01
      • 2015-06-26
      • 1970-01-01
      • 2012-09-17
      • 2018-08-31
      相关资源
      最近更新 更多