Combining image and text within a button in kivy

后端 未结 3 1839
庸人自扰
庸人自扰 2021-02-04 10:05

What\'s the preferred way to combine an image/icon and text within a button? For example, how would you create a button with text = \'my button\', and a graphical i

3条回答
  •  既然无缘
    2021-02-04 10:29

    Meanwhile, there is another way. You can use icon fonts such as Font Awesome and combine them with text.

    Either import the font directly and wrap the text in their font tag, or simply use some of the libraries that take care of that.

    #: import icon ...
    Button:
        markup: True
        text: "%s Comment" % icon('comment', 32)
        size_hint_x: None
        width: 100
    

    Kivy-iconfonts converts css/tff combinations that are distributed for web sites into a json format that it loads during runtime using the import statement as shown in the example above. I extended this in my fork to fetch Font Awesome icons during runtime and put them into the working directory of your application. That gives you the advantage of not having to distribute the fonts with the application.

提交回复
热议问题