Beginner’s Guide to Kivy Action Bar: Kivy Tutorial for Version 2.0.0

Posted by


Kivy is an open-source Python library for developing multitouch applications. It is designed to be cross-platform and runs on Windows, Mac, Linux, Android, and iOS. Kivy allows you to create applications with a natural user interface that is touch-enabled and can be run on various platforms without any modifications.

In this tutorial, I will be covering the Kivy Action Bar, which is a component of the Kivy library that allows you to add a top bar to your application with various customizable options.

Install Kivy 2.0.0:

Before we start working with the Kivy Action Bar, make sure you have Kivy 2.0.0 installed on your system. You can install Kivy using pip:

pip install kivy==2.0.0

Create a basic Kivy application:

Now let’s create a basic Kivy application to work with the Action Bar. Create a new Python file and add the following code to create a simple Kivy application with a button that will toggle the Action Bar:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.actionbar import ActionBar, ActionView, ActionButton

class TestApp(App):
    def build(self):
        layout = BoxLayout(orientation='vertical')

        action_bar = ActionBar()
        action_view = ActionView()
        action_button = ActionButton(text='Toggle Action Bar')
        action_button.bind(on_press=self.toggle_action_bar)

        action_view.add_widget(action_button)
        action_bar.add_widget(action_view)

        layout.add_widget(action_bar)

        return layout

    def toggle_action_bar(self, instance):
        action_bar = self.root.children[0]

        if action_bar.opacity == 1:
            action_bar.opacity = 0
        else:
            action_bar.opacity = 1

if __name__ == '__main__':
    TestApp().run()

Understanding the code:

In the above code, we created a simple Kivy application with a BoxLayout that contains an ActionBar. The ActionBar consists of an ActionView with an ActionButton that toggles the visibility of the ActionBar when pressed. When the ActionButton is pressed, it calls the toggle_action_bar function which changes the opacity of the ActionBar to show or hide it.

Run the application:

Save the Python file and run it using the following command:

python your_app_name.py

You should see a Kivy window with a top Action Bar containing a button. Clicking the button will toggle the visibility of the Action Bar.

Customizing the Action Bar:

You can customize the Action Bar by adding more widgets such as ActionItems, ActionOverflow, and ActionGroup. You can also change the appearance of the Action Bar by changing its background color, height, and other properties.

Conclusion:

In this tutorial, we covered the basics of working with the Kivy Action Bar in a Kivy application. We created a simple example that demonstrates how to add an Action Bar to your application and toggle its visibility using a button. You can further customize the Action Bar by adding more widgets and changing its appearance to suit your application’s needs.

0 0 votes
Article Rating
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@2pacOk4
2 months ago

Its presence makes the whole set up not looking cool

@2pacOk4
2 months ago

Thanks for this, but my concern is this: How do i remove the new kivy icon on the ACTION BAR

@pravinbaalaagv8948
2 months ago

Super bro
Thank you so much