-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFileBrowser.py
More file actions
61 lines (50 loc) · 2.22 KB
/
FileBrowser.py
File metadata and controls
61 lines (50 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''Authors: Aayushman Ghosh
Department of Electrical and Computer Engineering
University of Illinois Urbana-Champaign
(aghosh14@illinois.edu)
Version: v1.0
'''
# Importing the necessary libraries and modules. This is a simple GUI to load files that are to be used by the RL Algorithms
from tkinter import Tk, Button, Label, StringVar
from tkinter import filedialog
import os
def uigetfile():
def getfile():
files = filedialog.askopenfilenames(initialdir = os.getcwd(),
title = "Select a File",
filetypes = (("csv files",
"*.csv"),
("Mat files",
"*.mat*")))
label_file_explorer.configure(text="No. of Files Selected: "+str(len(files)))
myStrVar.set(list(files))
window = Tk()
window.title('File Selection')
window.geometry("350x150")
window.config(background = "white")
label_file_explorer = Label(window,
text = "File Explorer",
width = 50, height = 4,
fg = "blue")
button_explore = Button(window,
text = "Browse Files",
command = getfile)
button_exit = Button(window,
text = "Use Selected Files",
command = window.destroy)
label_file_explorer.grid(column = 4, row = 1)
global myStrVar
myStrVar = StringVar()
button_explore.grid(column = 4, row = 3)
button_exit.grid(column = 4,row = 5)
window.mainloop()
filenames = myStrVar.get()
file_nums = len(filenames[1:-1].split(','))
last_elem = filenames[1:-1].split(',')[-1]
if last_elem == '':
file_list = filenames[1:-1].split(',')[0].strip().strip('\'')
else:
file_list = []
for i in range(file_nums):
file_list.append(filenames[1:-1].split(',')[i].strip().strip('\''))
return file_list