O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding all files from a directory

The following code uses the os.walk() method to recursively walk through all the files looking for  .wav and .mp3 files, as follows (see code 5.03view.py):

def add_all_audio_files_from_directory(self):  directory_path = tkinter.filedialog.askdirectory()  if not directory_path: return  audio_files_in_directory =  self.get_all_audio_file_from_directory(directory_path)  for audio_file in audio_files_in_directory:     self.model.add_to_play_list(audio_file)     file_path, file_name = os.path.split(audio_file)     self.list_box.insert(tk.END, file_name) def get_all_audio_file_from_directory(self, directory_path):  audio_files_in_directory = []  for (dirpath, dirnames, filenames) in os.walk(directory_path): for audio_file in filenames: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required