How to use multiple UX Widgets in kivy | Python

Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.

UX Widgets:

Classical user interface widgets, ready to be assembled to create more complex widgets. There are multiple UX Widgets such as Label, Button, CheckBox, Image, Slider, Progress Bar, Text Input, Toggle button, Switch.

  • Label: The Label widget is for rendering text. It supports ascii and unicode strings.
  • Button: The Button is a Label with associated actions that are triggered when the button is pressed (or released after a click/touch).
  • CheckBox: CheckBox is a specific two-state button that can be either checked or unchecked.
  • Image: The Image widget is used to display an image.
  • Slider: The Slider widget looks like a scrollbar. It supports horizontal and vertical orientations, min/max values and a default value.
  • Progress Bar: ProgressBar widget is used to visualize the progress of some task.
  • TextInput: The TextInput widget provides a box for editable plain text.
  • Toggle Button: The ToggleButton widget acts like a checkbox. When you touch or click it, the state toggles between ‘normal’ and ‘down’ (as opposed to a Button that is only ‘down’ as long as it is pressed).
  • Switch: The Switch widget is active or inactive, like a mechanical light switch.

Here, we are going to use almost all these UX widgets So that you can understand how to use them in a single code.



Basic Approach:
1) import kivy
2) import kivyApp
3) import window
4) Set minimum version(optional)
5) Create the App class
6) Create the .kv file 
7) Make the run method/ run the App

Implementation of the Approach:

.py file:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Program to Show how to use multiple UX widget 
  
# import kivy module    
import kivy  
       
# base Class of your App inherits from the App class.    
# app:always refers to the instance of your application   
from kivy.app import App 
     
# this restrict the kivy version i.e  
# below this kivy version you cannot  
# use the app or software  
kivy.require('1.9.0')
  
# Here for providing colour to the background 
from kivy.core.window import Window
  
# Setting the window size
Window.size = (1120, 630)
  
# Add the App class
class ClassiqueApp(App):
    def build(FloatLayout):
        pass
  
# Run the App
if __name__ == '__main__':
    ClassiqueApp().run()

chevron_right


.kv file:

filter_none

edit
close

play_arrow

link
brightness_4
code

# .kv file implementation of the App
  
# Using Grid layout
GridLayout:
      
    cols: 4
    rows: 3
    padding: 10
  
    # Adding label
    Label:
        text: "I am a Label"
  
    # Add Button
    Button:
        text: "bouton 1"
  
    # Add CheckBox
    CheckBox:
        active: True
  
    # Add Image
    Image:
        source: 'html.png'
  
    # Add Slider
    Slider:
        min: -100
        max: 100
        value: 25
  
    # Add progress Bar
    ProgressBar:
        min: 50
        max: 100
  
    # Add TextInput
    TextInput:
        text: "Enter the text"
  
    # Add toggle Button
    ToggleButton:
        text: " Poetry Mode "
  
    # Add Switch 
    Switch:
        active: True
     

chevron_right


Output:



My Personal Notes arrow_drop_up

Competative Programmer

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.