0

Simply put, I want to have a GUI using Tkinter to open a dropdown window of a filder with 30+ CSV files so that I can select a single one of them and perform further actions on them after. Process order - Open directory -> Create Dropdown selection list -> select file -> Python selects file for further processing. So far I've been trying to mix the functions of Tkinter and os but with no luck.

import tkinter as tkr
import select
import sys
import os
#Basic idea of code with Os

print(' <select name="name">')
os.chdir("C:/Users/name/Desktop/folder")
for files in os.listdir("."):
    if files.endswith(".csv"):
        print('<option value="C:/users/'+files+'">'+files.replace('.csv','')+'</option>')    

#Understanding of Tkinter so far
master = tkr.Tk()
master.geometry("800x1200")
master.title("Select a File")

I know I need to find a way to set each CSV file as a variable and then assign them values for Tkinter to recognize and form a list from, but i don't have any clue how to do that.

Thank you.

1
  • Read up on filedialog Commented Feb 20, 2020 at 23:26

1 Answer 1

1

You can use ttk.Combobox as the dropdown selection:

import os
import tkinter as tk
from tkinter import ttk

folder = 'C:/Users/name/Desktop/folder'
filelist = [fname for fname in os.listdir(folder) if fname.endswith('.csv')]

master = tk.Tk()
master.geometry('1200x800')
master.title('Select a file')

optmenu = ttk.Combobox(master, values=filelist, state='readonly')
optmenu.pack(fill='x')

master.mainloop()
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This solution gave me a good direction to figure out how to continue on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.