-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilepicker_python3.py
More file actions
76 lines (65 loc) · 1.88 KB
/
filepicker_python3.py
File metadata and controls
76 lines (65 loc) · 1.88 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import tkinter
from tkinter import filedialog
import tkinter.messagebox
import sys
import pdb
def pickfile(path='.'): #add filetypes
root = Tkinter.Tk()
root.withdraw()
f = filedialog.askopenfilename(parent=root,title='Choose a file')
if f:
root.destroy()
del root
return f
else:
print ("No file picked, exiting!")
root.destroy()
del root
sys.exit()
def saveasfile(path='.', filetypes = [], defaultextension=''): #add filetypes
root = tkinter.Tk()
root.withdraw()
f = filedialog.asksaveasfilename(parent=root,title='Choose a filepath to save as',filetypes = filetypes,defaultextension=defaultextension)
if f:
root.destroy()
del root
return f
else:
print ("No file picked, exiting!")
root.destroy()
del root
sys.exit()
def pickfiles(path='.', filetypes = [], defaultextension=''):
root = tkinter.Tk()
root.withdraw()
f = filedialog.askopenfilenames(parent=root,title='Choose a file',filetypes = filetypes)
if f:
f=root.tk.splitlist(f)
root.destroy()
del root
return f
else:
print ("No file picked, exiting!")
root.destroy()
del root
sys.exit()
def pickdir(path='.'):
root = Tkinter.Tk()
root.withdraw()
dirname = filedialog.askdirectory(parent=root,initialdir=".",title='Please select a directory')
root.destroy()
if len(dirname ) > 0:
return dirname
else:
print ("No directory picked, exiting!")
sys.exit()
def askyesno(title = 'Display?',text = "Use interactive plotting?"):
root = Tkinter.Tk()
root.withdraw()
tf = tkMessageBox.askyesno(title, text)
root.destroy()
return tf
if __name__=='__main__':
fs = pickfiles(filetypes=[('AVI videos','*.avi'),('All files','*.*')])
print (fs)
print (type(fs))