In this video we’ll use the FileChooser FileChooserIconView and FileChooserListView to create a simple image viewing app with Kivy.
Kivy makes creating a FileChooser incredibly easy, as we’ll see in this video! You basically have two different options; the FileChooserIconView gives you a directory structure with little icons for folders and files, whereas the FileChooserListView gives you a more traditional text list of file directories and files that you can navigate.
Either is easy to use and I’ll walk you through it in this video.
Python Code: menu.py
GitHub Code: menu.py
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
# Designate Our .kv design file
Builder.load_file('menu.kv')
class MyLayout(Widget):
def selected(self, filename):
try:
self.ids.my_image.source = filename[0]
#print(filename[0])
except:
pass
class AwesomeApp(App):
def build(self):
return MyLayout()
if __name__ == '__main__':
AwesomeApp().run()
Kivy Design Code: menu.kv
GitHub Code: menu.kv
<MyLayout> id: my_widget BoxLayout: orientation: "vertical" size: root.width, root.height padding: 50 spacing: 20 Image: id: my_image source: "" FileChooserListView: id: filechooser on_selection: my_widget.selected(filechooser.selection)

Add comment