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)

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder