Python Kivy tutorials-Basic widgets – labels and buttons

In the previous chapter, we used the Label class, which is one of the multiple widgets that Kivy provides. You can think of widgets as interface blocks that we use to set up a GUI. Python Kivy has a complete set of widgets – buttons, labels, checkboxes, dropdowns, and many more. You can find them all in the API of Kivy under the package kivy.

We are going to learn the basics of how to create our own personalized widget without affecting the default configuration of Kivy widgets. In order to do that, we will use inheritance to create the widget class in the widgets.py file:

from kivy.app import App
class widgets(App):
    pass
if __name__ == '__main__':
    widgets().run()

widgets.kv file:

BoxLayout:
     Button:
          text: "Hello"
     Button:
          text: "Beautiful"
     Button:
          text: "World"

In this way we can play a lot with widgets, labels and buttons in Kivy. We will continue more in the next chapter.

Create your first kivy app

Aman Kharwal
Aman Kharwal

Data Strategist at Statso. My aim is to decode data science for the real world in the most simple words.

Articles: 1610

Leave a Reply

Discover more from thecleverprogrammer

Subscribe now to keep reading and get access to the full archive.

Continue reading