Python | File selection in kiwi

Kivy — it is a platform independent GUI tool in Python. Since it can run on Android, IOS, Linux, Windows, etc. It is mainly used to develop Android application, but that does not mean that it cannot be used in desktop applications.

Filechooser:

The FileChooser module provides various classes for describing, displaying, and viewing file systems. It`s as simple as My Computer, from which we can select any file on the system.

  • FileChooserListView displays the file entries as text items in a vertical list where folders can be collapsed and expanded.
  • FileChooserIconView presents icons and text from left to right, wrapping as needed.

Note . Both of the above dots provide scrolling, selection, and basic user experience.

  Basic Approach  1) import kivy 2) import kivyApp 3) import Boxlayot ​​4) Set minimum version (optional) 5 ) create layout class 6) create App class 7) create .kv file 8) return Layout / widget / Class (according to requirement) 9) Run an instance of the class or App 

Implementation of the approach :

.py file

# Program to explain how to use File chooser in kivy

 
# import nodded module

import kivy 

 
# Your application base class inherits from the application class.
# app: always refers to your application instance

from kivy. app import App 

  
# this limits the kivy version ie
# you cannot lower this version
# use application or software

kivy.require ( ` 1.9.0`

 
# BoxLayout arranges widgets either
# vertical mod that is on top
# different or horizontal
# this one by one.

from kivy.uix .boxlayout import BoxLayout

 
# create layout class

class Filechooser (BoxLayout):

def select ( self , * args):

  try : self . label.text = args [ 1 ] [ 0 ]

except : pass

 
# Create application class

class FileApp (App):

  def build ( self ):

return Filechooser ()

  
# run the application

if __ name__ = = ` __main__` :

FileApp (). run ()

.kv file

#, kv file implementation

 
& lt; Filechooser & gt; :

 

label: label

  

  # Provide orientation

orientation: `vertical`

  

  # File list creation / icon view

 

BoxLayout:

  # Create a list on one side

FileChooserListView:

canvas.before:

Color:

rgb:. 4 ,. 5 ,. 5

  Rectangle:

  pos: self . pos

size: self . size

  on_selection: root.select ( * args)

 

# Create an icon from another sides

FileChooserIconView:

canvas.before:

Color:

  rgb:. 5 ,. 4 ,. 5

Rectangle:

pos: self .pos

  size: self . size

on_selection: root.select ( * args)

 

# Add shortcut

  Label:

id : label

size_hint_y:. 1

canvas.before:

Color:

  rgb :. 5 ,. 5 ,. 4

Rectangle:

pos: self . pos

size: self . size

  

Output: