How to get a list of file into a listbox in tkinter

A class you can use to get list of files into a listbox. I called it FileList and when you make an istance of this class you pass the file type as argument to see the files in the listbox, like this:

FileList(“mp4”)

The output will be something like this:

The files will be listed into the listbox

Put the type of file as an argument to get the list of that particular file type

from glob import glob
import tkinter as tk


class FileList:
	def __init__(self, ft):
		root = tk.Tk()
		root.geometry("400x800")
		lb = tk.Listbox(root)
		lb.configure(bg="gold")
		lb.pack(fill="both", expand=True)
		fl = glob("*." + ft)
		for f in fl:
		    lb.insert(0,f)
		root.mainloop()



FileList("py")

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.