10 examples of 'tkinter askopenfilename' in Python

Every line of 'tkinter askopenfilename' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
38def ask_file(title):
39 root = Tk()
40 filename = filedialog.askopenfilename(parent=root, title=title)
41 root.destroy()
42 return filename
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

132def askopenfilenames(**options):
133 """Ask for multiple filenames to open
134
135 Returns a list of filenames or empty list if
136 cancel button selected
137 """
138 options["multiple"]=1
139 return Open(**options).show()
42def askfilepath(filename):
43 return askopenfilename3(
44 title = "Please select '%s':" % filename,
45 initialfile=filename,
46 filetypes=[(filename,filename)]
47 )
534def asksavefile(self):
535 dir, base = self.defaultfilename("save")
536 if not self.savedialog:
537 self.savedialog = tkFileDialog.SaveAs(master=self.text,
538 filetypes=self.filetypes)
539 return self.savedialog.show(initialdir=dir, initialfile=base)
356@contextmanager
357def askSaveAsFile(**kw):
358 file = filedialog.asksaveasfile(**kw)
359 try:
360 yield file
361 finally:
362 file.close()
510def askdirectory(self, **args):
511 """Returns a user-selected directory name. Tries to return the 'initialdir' default if nothing selected """
512 if args['initialDir'] and len(args['initialDir'])>0:
513 dirname = tkFileDialog.askdirectory(initialdir = args['initialDir'], **self.dir_opt)
514 else:
515 dirname = tkFileDialog.askdirectory(**self.dir_opt)
516 print dirname
517 print args
518 if not dirname:
519 print "no directory name given"
520 if args['initialDir']:
521 return args['initialDir']
522 else:
523 return ''
524 else:
525 print dirname
526 return dirname
24def FileOpenDialog( message, wildcard, style=0, defaultDir=os.getcwd(), defaultFile='' ):
25 """Generic file open dialog."""
26 style = style | wx.OPEN | wx.CHANGE_DIR
27 return FileDialog( message, wildcard, style, defaultDir, defaultFile )
64def file_dialog(message, wildcard, style, ok_handler, default_file=''):
65 last_opened_dir_file = os.path.join(dirs.CACHE_DIR, 'last_opened_dir')
66
67 last_opened_dir = None
68
69 if os.path.exists(last_opened_dir_file):
70 with open(last_opened_dir_file, 'r') as fp:
71 last_opened_dir = fp.read().strip()
72
73 if last_opened_dir is None or len(last_opened_dir) == 0:
74 last_opened_dir = os.path.expanduser('~')
75
76 dlg = wx.FileDialog(
77 None, message, last_opened_dir, default_file, wildcard, style)
78
79 try:
80 if dlg.ShowModal() == wx.ID_OK:
81 last_opened_dir = dlg.GetDirectory()
82
83 path = os.path.join(dlg.GetDirectory(), dlg.GetFilename())
84 ok_handler(dlg, path)
85 finally:
86 dlg.Destroy()
87
88 if not os.path.exists(dirs.CACHE_DIR):
89 os.makedirs(dirs.CACHE_DIR)
90
91 with open(last_opened_dir_file, 'w+') as fp:
92 fp.write(last_opened_dir)
437def select_outfile(filt = '*', title=''):
438 root = Tkinter.Tk()
439 root.withdraw()
440 filetypes = [('Output',filt)]
441 filename = tkFileDialog.SaveAs(filetypes=filetypes,defaultextension=filt,title=title).show()
442 root.destroy()
443 if filename:
444 return filename
445 else:
446 return None
167@eel.expose
168def ask_files():
169 """ Ask the user to select one or more files """
170 root = Tk()
171 root.withdraw()
172 root.wm_attributes('-topmost', 1)
173 file_paths = askopenfilenames(parent=root)
174 root.update()
175 return file_paths

Related snippets