0
我想創建一個kivy程序,它從文本輸入中獲取一個數字,在數字中添加一個數字並寫入標籤。kivy將變量添加到根部件
但該程序沒有接受我的變量作爲根部件的一部分。
這裏是PROGRAMM:
import kivy
from kivy.app import App
from kivy.uix.scatter import Scatter
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import *
from kivy.graphics.vertex_instructions import *
from kivy.graphics.context_instructions import *
kivy.lang.Builder.load_string('''
<my_layout>:
orientation: 'vertical'
canvas:
Color
rgba: 10, 10, 0, 1
Label:
id: label0
text: 'Wie viel Wiegt das Ei in gramm?'
font_size: 50
TextInput:
id: my_textinput
font_size: 100
size_hint_y: None
height: 100
Button:
id: my_button
height: 100
text: 'button'
canvas:
Color:
rgba: 0, 0, 20, 1
on_press: root.berechnen(my_textinput.text)
Label:
id: label1
text: root.var
''')
class my_layout(BoxLayout):
def __init__(self, **kwargs):
super(my_layout,self).__init__(**kwargs)
self.var = self.number
def berechnen(self, txt):
self.number = txt
class Add(App):
def build(self):
return my_layout()
if __name__ == "__main__":
Add().run()