The code does not work as expected. (python and kivy)

Asked

Viewed 178 times

-1

I cannot change the name of Label 1 or Label 2 through the click function. The program shows only "hi" on the console.

Python code:

import kivy
kivy.require("1.9.1")
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout


class MinhaTela(BoxLayout):
    def click(self):
        print("oi")
        self.ids.lb1.text: ""
        self.ids.lb2.text: "10"


class Estudo(App):
    pass


e1 = Estudo()
e1.run()

Kivy code:

<MinhaTela@BoxLayout>
orientation: "vertical"

Button:
    text: "OK"
    on_press: root.click()
Label:
    text: "Label 1"
    id: lb1
Label:
    text: "Label 2"
    id: lb2

MinhaTela:

1 answer

0

You have to use the same sign instead of the two dots.

import kivy
kivy.require("1.9.1")
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout


class MinhaTela(BoxLayout):
    def click(self):
        print("oi")
        self.ids.lb1.text = ""
        self.ids.lb2.text = "10"


class EstudoApp(App):
    def build(self):
        return MinhaTela()


e1 = EstudoApp()
e1.run()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.