Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

from kivy.app import App
from kivy.lang.builder import Builder
from kivy.properties import StringProperty
from kivy.uix.boxlayout import BoxLayout


class Container(BoxLayout):
    message = StringProperty()

    def retranslate(self, language):
        texts = {"en": "Hello World", "fr": "Salut monde"}
        self.message = texts.get(language, "")


Builder.load_string(
    """
<Container>:
    orientation: 'vertical'
    Button:
        text: root.message
    Button:
        text: "Eng"
        on_press: root.retranslate("en")
    Button:
        text: "Fra"
        on_press: root.retranslate("fr")
"""
)


class MyApp(App):
    def build(self):
        w = Container()
        w.retranslate("en")
        return w


if __name__ == "__main__":
    MyApp().run()

Comment

PREVIOUS NEXT
Code Example
Python :: concat dataset 
Python :: why mentioning user agent in request library 
Python :: import external script in django views 
Python :: nltk document 
Python :: how to find left top width and height on an image using python 
Python :: python find multiple matches in string 
Python :: how to draw play area for a game in python turtle 
Python :: create loading in pyqt 
Python :: python-wordpress-xmlrpc get post id 
Python :: python numpy read from stdin 
Python :: pandas get data from upper row 
Python :: Only show legend of inner donut 
Python :: Reading from a file way01 
Python :: Python Syntax of for Loop 
Python :: Python Raw String to ignore escape sequence 
Python :: python property class 
Python :: How to deal with SettingWithCopyWarning in Pandas 
Python :: scraped text in Russian encoding python 
Python :: jittering(adding back rounded up values) 
Python :: Generate bootstrap replicate of 1D data that return a particular operation 
Python :: different accuracy score for knn 
Python :: Create an x amount of unique random fixed size strings 
Python :: proclus python 
Python :: hashing algorithms in python 
Python :: For_else 
Python :: install mangadex python 
Python :: lunarcalendar python 
Python :: Delete files in folder by extension 
Python :: how to get scrapy output file in xml file 
Python :: np choose explain 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =