Change language

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

 
"Filechooser" :

 

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:

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method