Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code which I am trying to open different files from different folders and use those files to plot a graph. I am using askdirectory in tkinter and storing the filenames into a listbox.
Python
<        def ask():
            global path
            path = filedialog.askdirectory() # select directory 
            statusbar1.config(text=path) # update the text of Label with directory path 
            x=next(os.walk(path))[2] # list of files 
                                       
            for each_item in range(len(x)):          
                listb.insert(tk.END, x[each_item])
                listb.itemconfig(each_item, bg = "#8c92ac",fg= "#161327")> "> 
Then I want to choose a filename from the listbox and use the content to plot a graph.

Python
<
        def paths_selected():
            global paths,spectrum_data, xaxis, var, path, filenames
            filenames = [listb.get(i) for i in listb.curselection()]>

What I have tried:
Function "paths_selected" is operated by a button (browse). This will populate the listbox from files from any folder everytime I click the browse button. But I can only use files from one directory to plot the graph. I want to be able to choose a file from a different directory and use both files to plot the graph. Any ideas of how to do that?
Posted
Comments
Richard MacCutchan 29-Oct-22 3:53am    
You could use two listboxes, or do two calls to askdirectory and store the complete path in the listbox.
Member 15813275 30-Oct-22 10:21am    
Is there a way to use the same listbox? Because eventually I would like to navigate through directories and use files from anywhere. Not essentially just two. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900