How to Use Button, TextInput, and ToggleButton in Kivy Python

 

The goal of this series is to teach you how to use Button, TextInput, and ToggleButton in Kivy. 

Part 1: Button In Kivy 

Let’s begin with the button in Kivy — something you'll use in almost every project. Here’s what that structure looks like:

from kivy.app import App
from kivy.uix.textinput import Button

class MyKivy(App):
    def build(self):
        return Button(text="Click me!", size=(200,50),
                        size_hint=(None,None),
                        pos_hint={'center_x': 0.5, 'center_y': 0.5}


            )

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


Part 2: TextInput In Kivy

Let’s add a simple TextInput so something shows up on the screen.

We’ll import TextInput from kivy.uix.textinput, and return it in our build() function:

from kivy.app import App

from kivy.uix.textinput import TextInput

class MyKivy(App):

    def build(self):

        return TextInput(text="Enter your name", size_hint=(None,None), size=(200,50),pos_hint={'center_x': 0.5, 'center_y':0.5})

if __name__ == "__main__":

    MyKivy().run()


Part 3: ToggleButton In Kivy

Let’s add a simple ToggleButton so something shows up on the screen.

We’ll import ToggleButton from kivy.uix.togglebutton, and return it in our build() function:


from kivy.app import App

from kivy.uix.togglebutton import ToggleButton

class MyKivy(App):

    def build(self):

        return ToggleButton(text="Unchecked", size_hint=(None,None), size=(200,50),pos_hint={'center_x': 0.5, 'center_y':0.5}, allow_no_selection=False)

if __name__ == "__main__":

    MyKivy().run()



If you enjoyed this video, please likesubscribe, and hit the bell icon so you don’t miss the next lesson.
And if anything was unclear, drop a comment — I’m always here to help.

Thanks for watching — I’ll see you in the next tutorial.
Until then, peace and happy coding!

Social Media Accounts: 

Youtube:

Pinterest:

Facebook :

Instagram:

Dribbble:

Behance:


Download Source Files:

Download

Post a Comment

Previous Post Next Post