Button with borders | Python & Kivy

Posted by

To create a button with borders in Python with Kivy, we will first need to install Kivy if it is not already installed. To do this, you can use pip to install Kivy by running the following command:

pip install kivy

Once Kivy is installed, you can start creating your button with borders using Python code. Below is an example of how to create a simple Kivy app with a button that has borders.

First, create a Python file (e.g. main.py) and import the necessary modules:

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout

Next, create a class for your Kivy app:

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

        # Create a button with borders
        button = Button(text='Button with borders', background_color=(1,1,1,1), border=(2,2,2,2))
        layout.add_widget(button)

        return layout

In the code above, we create a BoxLayout to hold our button. We then create a Button widget with the desired text and set the background color to white. The border property is set to specify the thickness of the borders on all sides of the button.

Finally, we instantiate the BorderButtonApp class and run the app by calling the run() method:

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

Save your Python file and run it using the command line or your favorite IDE.

python main.py

You should see a Kivy window pop up with a button that has borders around it. You can customize the button further by changing the border thickness or color, as well as the background color and text style.

That’s it! You have successfully created a button with borders in Python using Kivy. Feel free to experiment with different properties and styles to create the button that fits your app’s design. Happy coding!

0 0 votes
Article Rating
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@CARIOCAJJ36
1 month ago

Show de bola

@CARIOCAJJ36
1 month ago

Isso tudo só para fazer um botão 😢

@EndrioEstudante
1 month ago

Valeu mano.