Lets say I have folder with music.
--Iron Maiden
--Prowler
--Sanctuary
--Iron Maiden
--etc
And I have class with method in it which is finding all music in this folder and adding information about this song to the list.
Little example, just getting path to all files in folder.
from tkinter import Frame, Listbox, Menu, BOTH, filedialog, Tk, LEFT
import os
class GUI(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.list = Listbox(parent)
self.parent = parent
self.init_ui()
def init_ui(self):
menu_bar = Menu(self.parent)
self.parent.config(menu=menu_bar)
file_menu = Menu(menu_bar, tearoff=False)
self.list.pack(side=LEFT)
file_menu.add_command(label="Choose folder with music",
underline=0, command=self.get_music)
menu_bar.add_cascade(label="File", underline=0, menu=file_menu)
def get_music(self):
dir_name = filedialog.askdirectory(parent=self, initialdir="/",
title='Please select a directory')
self.config(cursor="wait")
self.update()
for data in os.walk(dir_name):
for filename in data[2]:
self.list.insert(0,os.path.join(data[0], filename))
GUI(Tk()).mainloop()
Lets imagine that get_music lasts for minutes and user doesn't know what is going on, he is bored and scared.
I want to show him new window with listbox and progress bar and in the listbox show him what now is doing my program and in the progress bar show him progress.
Here I've found very good example and for a few hours I've been trying to make it work with what I have, but whatever I do it doesn't work.
I've even tried to start test thread from get_music(), but id didn't work.
How can I connect what I have with what is in the example ?
Or maybe there is other, better way to do what I want to do ?