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

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically