label not updated in kivy it is write on top of the origenal one

Viewed 25

Why in my simple code the label text not updating jus overwrite us you see ? see the button text updated but label not

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.lang import Builder
#from kivy.uix.floatlayout import FloatLayout

Builder.load_file("update_label.kv")


class MyLayout(Widget):
    def press(self):
        # Create varable for our widget
        name = self.ids.name_input.text
        # update the Label
        self.ids.name_label.text = f'Hello {name}'
        
        self.ids.btn.text = f"Hello {name}"

        self.ids.label.text = f"Hello {name}"

class Update_LabelApp(App):
    def build(self):
        return MyLayout()

.kv file

<MyLayout>:
    BoxLayout:
        orientation: "vertical"
        size: root.width, root.height
    
        Label:
            id: name_label
            text: "What is your Name?"

        TextInput:
            id: name_input
            multiline: False
            size_hint: (1, .5)

        Button:
            id: btn
            text: "Submit"
            size_hint: (1, .5)
            font_size: 32
            on_press: root.update_label()

        Label:
            id: label
            text: "hi"

Any suggestion ?

0 Answers
Related