how to change a kivy button text in kivy lang from python file

Solutions on MaxInterview for how to change a kivy button text in kivy lang from python file by the best coders in the world

showing results for - "how to change a kivy button text in kivy lang from python file"
Tomas
15 Oct 2020
1from kivy.app import App
2from kivy.lang.builder import Builder
3from kivy.properties import StringProperty
4from kivy.uix.boxlayout import BoxLayout
5
6
7class Container(BoxLayout):
8    message = StringProperty()
9
10    def retranslate(self, language):
11        texts = {"en": "Hello World", "fr": "Salut monde"}
12        self.message = texts.get(language, "")
13
14
15Builder.load_string(
16    """
17<Container>:
18    orientation: 'vertical'
19    Button:
20        text: root.message
21    Button:
22        text: "Eng"
23        on_press: root.retranslate("en")
24    Button:
25        text: "Fra"
26        on_press: root.retranslate("fr")
27"""
28)
29
30
31class MyApp(App):
32    def build(self):
33        w = Container()
34        w.retranslate("en")
35        return w
36
37
38if __name__ == "__main__":
39    MyApp().run()
40
41