Python tkfiledialog.askopenfilename() Examples
The following are 30
code examples of tkfiledialog.askopenfilename().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tkFileDialog
, or try the search function
.
Example #1
Source File: view.py From ms_deisotope with Apache License 2.0 | 6 votes |
def main(): base = Tk() base.title("ms_deisotope Spectrum Viewer") tk.Grid.rowconfigure(base, 0, weight=1) tk.Grid.columnconfigure(base, 0, weight=1) app = SpectrumViewer(base) app.do_layout() try: fname = sys.argv[1] except IndexError: fname = None # fname = tkfiledialog.askopenfilename() print("initial value", fname) app.ms_file_name = fname app.mainloop()
Example #2
Source File: kimmo.py From razzy-spinner with GNU General Public License v3.0 | 6 votes |
def loadTypetoTarget(self, fileType, targetWindow, ftype = None): if not (fileType and targetWindow): return from tkFileDialog import askopenfilename ftypes = [(fileType, fileType)] filename = askopenfilename(filetypes=ftypes, defaultextension=fileType) self.loadIntoWindow(filename, targetWindow) # set the config menu to blank self.configsMenuButton.configure(text='<none>') # !!! remember to reset all the filenames as well! if filename: if ftype == 'l': self.lexfilename = filename elif ftype == 'r': self.rulfilename = filename
Example #3
Source File: MappingDriver.py From LSDMappingTools with MIT License | 6 votes |
def print_welcome(): print("\n\n=======================================================================") print("Hello there, I am the going to help you plot LSDTopoTools data!") print("You will need to tell me where the parameter file is.") print("Use the -wd flag to define the working directory.") print("If you dont do this I will assume the data is in the same directory as this script.") print("=======================================================================\n\n ") from Tkinter import Tk from tkFileDialog import askopenfilename Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file return filename #=============================================================================
Example #4
Source File: chart.py From razzy-spinner with GNU General Public License v3.0 | 6 votes |
def load_chart(self, *args): "Load a chart from a pickle file" filename = askopenfilename(filetypes=self.CHART_FILE_TYPES, defaultextension='.pickle') if not filename: return try: chart = pickle.load(open(filename, 'r')) self._chart = chart self._cv.update(chart) if self._matrix: self._matrix.set_chart(chart) if self._matrix: self._matrix.deselect_cell() if self._results: self._results.set_chart(chart) self._cp.set_chart(chart) except Exception, e: raise tkMessageBox.showerror('Error Loading Chart', 'Unable to open file: %r' % filename)
Example #5
Source File: DeviceManager.py From python-dvr with MIT License | 6 votes |
def flash(self): self.fl_state.set("Processing...") filename = askopenfilename( filetypes=((_("Flash"), "*.bin"), (_("All files"), "*.*")) ) if filename == "": return if len(self.table.selection()) == 0: _mac = "all" else: _mac = self.table.item(self.table.selection()[0], option="values")[4] result = ProcessCMD( ["flash", _mac, self.passw.get(), filename, self.fl_state.set] ) if ( hasattr(result, "keys") and "Ret" in result.keys() and result["Ret"] in CODES.keys() ): showerror(_("Error"), CODES[result["Ret"]])
Example #6
Source File: Airtun-ng.py From Airvengers with GNU General Public License v2.0 | 6 votes |
def browse_file(self): self.fname = tkFileDialog.askopenfilename(filetypes = (("Template files", "*.type"), ("All files", "*"))) # def submit(self): # print('Name: {}'.format(self.entry_name.get())) # print('Email: {}'.format(self.entry_email.get())) # print('Comments: {}'.format(self.text_comments.get(1.0, 'end'))) # self.clear() # tkMessageBox.showinfo(title = 'Explore California Feedback', message = 'Comments Submitted!') # # def clear(self): # self.entry_name.delete(0, 'end') # self.entry_email.delete(0, 'end') # self.text_comments.delete(1.0, 'end') #
Example #7
Source File: __init__.py From GeoVis with MIT License | 6 votes |
def AskShapefilePath(text="unknown task"): """ Pops up a temporary tk window asking user to visually choose a shapefile. Returns the chosen shapefile path as a text string. Also prints it as text in case the user wants to remember which shapefile was picked and hardcode it in the script. | __option__ | __description__ | --- | --- | *text | an optional string to identify what purpose the shapefile was chosen for when printing the result as text. """ tempwindow = tk.Tk() tempwindow.state("withdrawn") shapefilepath = tkFileDialog.askopenfilename(parent=tempwindow, filetypes=[("shapefile",".shp")], title="choose shapefile for "+text) tempwindow.destroy() print("you picked the following shapefile for <"+str(text)+">:\n"+str(shapefilepath)+"\n\n") return shapefilepath
Example #8
Source File: gcode_reader.py From omg-tools with GNU Lesser General Public License v3.0 | 6 votes |
def load_file(self, file=None): if file is None: file = tkfiledialog.askopenfilename(filetypes=[('GCode files', '.nc'), ('all files','.*')]) self.filepath = file.rsplit('/',1)[0] # save file path without the file name if file: try: data = open(file, 'rb') except Exception as details: tkmessagebox.showerror(('Error'),details) return else: try: data = open(file, 'rb') except Exception as details: print(details) return self.file = data
Example #9
Source File: gui.py From snn_toolbox with MIT License | 6 votes |
def load_settings(self, s=None): """Load a perferences settings.""" if s is None: if self.restore_last_pref: self.restore_last_pref = False if not os.path.isdir(self.default_path_to_pref): return path_to_pref = os.path.join(self.default_path_to_pref, '_last_settings.json') if not os.path.isfile(path_to_pref): return else: path_to_pref = filedialog.askopenfilename( defaultextension='.json', filetypes=[("json files", '*.json')], initialdir=self.default_path_to_pref, title="Choose filename") s = json.load(open(path_to_pref)) self.set_preferences(s)
Example #10
Source File: strap_beam_gui.py From Structural-Engineering with BSD 3-Clause "New" or "Revised" License | 6 votes |
def open_existing(self, *args): filename = tkFileDialog.askopenfilename() extension = filename.split('.')[-1] if filename is None: return elif extension not in ['strapbm']: tkMessageBox.showerror("ERROR!!","Selected File not a .strapbm file") return else: calc_file = open(filename,'r') calc_data = calc_file.readlines() calc_file.close() i=0 for line in calc_data: value = line.rstrip('\n') self.inputs[i].set(value) i+=1
Example #11
Source File: chartparser_app.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def load_chart(self, *args): "Load a chart from a pickle file" filename = askopenfilename(filetypes=self.CHART_FILE_TYPES, defaultextension='.pickle') if not filename: return try: chart = pickle.load(open(filename, 'r')) self._chart = chart self._cv.update(chart) if self._matrix: self._matrix.set_chart(chart) if self._matrix: self._matrix.deselect_cell() if self._results: self._results.set_chart(chart) self._cp.set_chart(chart) except Exception, e: raise tkMessageBox.showerror('Error Loading Chart', 'Unable to open file: %r' % filename)
Example #12
Source File: sqlite_bro.py From sqlite_bro with MIT License | 6 votes |
def load_script(self): """load a script file, ask validation of detected Python code""" filename = filedialog.askopenfilename( initialdir=self.initialdir, defaultextension='.sql', filetypes=[("default", "*.sql"), ("other", "*.txt"), ("all", "*.*")]) if filename != '': self.set_initialdir(filename) text = os.path.split(filename)[1].split(".")[0] with io.open(filename, encoding=guess_encoding(filename)[0]) as f: script = f.read() sqls = self.conn.get_sqlsplit(script, remove_comments=True) dg = [s for s in sqls if s.strip(' \t\n\r')[:5] == "pydef"] if dg: fields = ['', ['In Script File:', filename, 'r', 100], '', ["Python Script", "".join(dg), 'r', 80, 20]] create_dialog(("Ok for this Python Code ?"), fields, ("Confirm", self.load_script_ok), [text, script]) else: new_tab_ref = self.n.new_query_tab(text, script)
Example #13
Source File: sqlite_bro.py From sqlite_bro with MIT License | 6 votes |
def attach_db(self): """attach an existing database""" filename = filedialog.askopenfilename( initialdir=self.initialdir, defaultextension='.db', title="Choose a database to attach ", filetypes=[("default", "*.db"), ("other", "*.db*"), ("all", "*.*")]) attach = os.path.basename(filename).split(".")[0] avoid = {i[1]: 0 for i in get_leaves(self.conn, 'attached_databases')} att, indice = attach, 0 while attach in avoid: attach, indice = att + "_" + str(indice), indice + 1 if filename != '': self.set_initialdir(filename) attach_order = "ATTACH DATABASE '%s' as '%s' " % (filename, attach) self.conn.execute(attach_order) self.actualize_db()
Example #14
Source File: dialog_elements.py From Enrich2 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def body(self, master, row, columns=DEFAULT_COLUMNS, **kwargs): """ Place the required elements using the grid layout method. Returns the number of rows taken by this element. """ label = ttk.Label(master, text=self.text) label.grid(row=row, column=0, columnspan=1, sticky="e") self.entry = ttk.Entry(master, textvariable=self.value) self.entry.grid(row=row, column=1, columnspan=columns - 1, sticky="ew") if self.directory: self.choose = ttk.Button( master, text="Choose...", command=lambda: self.value.set(tkFileDialog.askdirectory()), ) else: self.choose = ttk.Button( master, text="Choose...", command=lambda: self.value.set(tkFileDialog.askopenfilename()), ) self.choose.grid(row=row + 1, column=1, sticky="w") if self.optional: self.clear = ttk.Button( master, text="Clear", command=lambda: self.value.set("") ) self.clear.grid(row=row + 1, column=2, sticky="e") return 2
Example #15
Source File: Skeleton_Key.py From firmware_password_manager with MIT License | 5 votes |
def local_fetch(self): """ Popup simple local navigation dialog. """ self.logger.info("%s: activated" % inspect.stack()[0][3]) self.key_item = tkFileDialog.askopenfilename(title="Local object", message="Select local object:", parent=self.root) if self.key_item: self.status_string.set('Object found.') self.handle_key_item() else: self.status_string.set('No object selected.')
Example #16
Source File: Main_GUI_Tabs.py From CNNArt with Apache License 2.0 | 5 votes |
def open_explorer(self): name = askopenfilename() self.path_cnn_entry.insert(0, name) print(self.path_cnn_entry.get())
Example #17
Source File: Skeleton_Key.py From firmware_password_manager with MIT License | 5 votes |
def read_remote(self): """ Handle server connection, keyfile selection and remote volume dismount. """ self.logger.info("%s: activated" % inspect.stack()[0][3]) tmp_directory = "/tmp/sk/mount" if not os.path.exists(tmp_directory): os.makedirs(tmp_directory) try: self.logger.info("%s: %s" % (inspect.stack()[0][3], "Mounting")) msb.mount_share_at_path_with_credentials(self.remote_hostname.get(), tmp_directory, self.remote_username.get(), self.remote_password.get()) self.key_item = tkFileDialog.askopenfilename(initialdir=tmp_directory, title="Remote object", message="Select remote object:", parent=self.root) self.logger.info("%s: %s" % (inspect.stack()[0][3], self.key_item)) if self.key_item: self.status_string.set('Object found.') self.handle_key_item() else: self.status_string.set('No object selected.') self.logger.info("%s: %s" % (inspect.stack()[0][3], "Dismounting")) umount_results = subprocess.check_output(["/usr/sbin/diskutil", "unmount", tmp_directory]) self.logger.info(umount_results) except Exception as exception_message: self.logger.error(exception_message)
Example #18
Source File: toolbox.py From goreviewpartner with GNU General Public License v3.0 | 5 votes |
def open_all_file(parent,config,filetype): import tkFileDialog initialdir = grp_config.get(config[0],config[1]) filename=tkFileDialog.askopenfilename(initialdir=initialdir, parent=parent,title=_("Select a file"),filetypes =filetype ) if filename: initialdir=os.path.dirname(filename) grp_config.set(config[0],config[1],initialdir) filename=unicode(filename) return filename
Example #19
Source File: mlnquery.py From pracmln with BSD 2-Clause "Simplified" License | 5 votes |
def ask_load_project(self): filename = askopenfilename(initialdir=self.dir, filetypes=[('PRACMLN project files', '.pracmln')], defaultextension=".pracmln") if filename and os.path.exists(filename): self.load_project(filename) else: logger.info('No file selected.') return
Example #20
Source File: mlnlearn.py From pracmln with BSD 2-Clause "Simplified" License | 5 votes |
def ask_load_project(self): filename = askopenfilename(initialdir=self.dir, filetypes=[('PRACMLN project files', '.pracmln')], defaultextension=".pracmln") if filename and os.path.exists(filename): self.load_project(filename) else: logger.info('No file selected.') return
Example #21
Source File: widgets.py From pracmln with BSD 2-Clause "Simplified" License | 5 votes |
def import_file(self): filename = askopenfilename(initialdir=self.dir, filetypes=self.fsettings.get('ftypes'), defaultextension=self.fsettings.get('extension', '.mln')) if filename: fpath, fname = ntpath.split(filename) self.dir = os.path.abspath(fpath) content = mlnpath(filename).content if self.import_hook is not None: self.import_hook(fname, content) self.update_file_choices() self.selected_file.set(fname) self.dirty = True
Example #22
Source File: gui.py From sky3ds.py with MIT License | 5 votes |
def write_save(self): try: disk = sd_card.disk_path except: raise Exception("Please open a disk before attempting to write a save.") file_path = tkFileDialog.askopenfilename( initialdir = os.path.expanduser('~/Desktop'), filetypes=[ ("3DS Save","*.sav")] ) if file_path: # follow symlink file_path = os.path.realpath(file_path) self.message = "Writing %s" % os.path.basename(file_path) progress_bar = progress_bar_window("Writing Save", self.message, mode = "indeterminate", maximum = 100, task = "write save") root.wait_visibility(progress_bar.progress) progress_bar.start_indeterminate() sd_card.write_savegame(file_path) progress_bar.progress_complete() controller.fill_rom_table() else: return
Example #23
Source File: gui.py From sky3ds.py with MIT License | 5 votes |
def write_rom(self): try: disk = sd_card.disk_path except: raise Exception("Please open a disk before attempting to write a rom.") file_path = tkFileDialog.askopenfilename( initialdir = os.path.expanduser('~/Desktop'), filetypes=[ ("3DS Rom","*.3ds")] ) if file_path: # follow symlink file_path = os.path.realpath(file_path) # if the template data doesn't exist we might as well just shut it down right here. If the progress window shows up the exception will stop the process so I can't destrot that toplevel. if not self.get_rom_template_data(file_path): tkMessageBox.showinfo("Missing Template Data", "Template entry not found.") return None # get rom size and calculate block count rom_size = os.path.getsize(file_path) self.message = "Writing %s" % os.path.basename(file_path) progress_bar = progress_bar_window("Writing Rom", self.message, mode = "determinate", maximum = rom_size, task = "write") root.wait_visibility(progress_bar.window) sd_card.write_rom(file_path, progress=progress_bar) controller.fill_rom_table() else: return
Example #24
Source File: WaterPanel.py From Pirates-Online-Rewritten with BSD 3-Clause "New" or "Revised" License | 5 votes |
def select_shader(self): default_directory = base.config.GetString('water-panel-default-shader-path', '.') filename = askopenfilename(initialdir=default_directory, filetypes=[('CG', 'cg')], title='Select Shader') if not filename: return else: print filename self.set_shader(filename)
Example #25
Source File: WaterPanel.py From Pirates-Online-Rewritten with BSD 3-Clause "New" or "Revised" License | 5 votes |
def select_alpha_texture(self): default_directory = base.config.GetString('water-panel-default-texture-path', '.') filename = askopenfilename(initialdir=default_directory, filetypes=[('BMP JPG TIF', 'bmp jpg tif')], title='Select Alpha Texture') if not filename: return else: print filename self.set_alpha_texture(filename)
Example #26
Source File: WaterPanel.py From Pirates-Online-Rewritten with BSD 3-Clause "New" or "Revised" License | 5 votes |
def select_texture(self): default_directory = base.config.GetString('water-panel-default-texture-path', '.') filename = askopenfilename(initialdir=default_directory, filetypes=[('BMP JPG TIF', 'bmp jpg tif')], title='Select Texture') if not filename: return else: print filename self.set_texture(filename)
Example #27
Source File: WaterPanel.py From Pirates-Online-Rewritten with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _load_water_parameters(self): default_directory = base.config.GetString('water-panel-default-path', '.') filename = askopenfilename(initialdir=default_directory, filetypes=[('WTR', 'wtr')], title='Open Water File') if not filename: return False return self.load_region(filename)
Example #28
Source File: tkconch.py From learn_python3_spider with MIT License | 5 votes |
def getIdentityFile(self): r = tkFileDialog.askopenfilename() if r: self.identity.delete(0, Tkinter.END) self.identity.insert(Tkinter.END, r)
Example #29
Source File: PPA.py From PhotoPolarAlign with The Unlicense | 5 votes |
def get_file(self, hint): ''' User wants to select an image file ''' import tkFileDialog from os.path import splitext, dirname, basename options = {} options['filetypes'] = [('JPEG files', '.jpg .jpeg .JPG .JPEG'), ('all files', '.*')] options['initialdir'] = self.imgdir titles = {} titles['v'] = 'The vertical image of the Celestial Pole region' titles['h'] = 'The horizontal image of the Celestial Pole region' titles['i'] = 'The horizontal image after Alt/Az adjustment' options['title'] = titles[hint] img = tkFileDialog.askopenfilename(**options) if img: wcs = splitext(img)[0] + '.wcs' if self.happy_with(wcs, img): self.update_solved_labels(hint, 'active') else: self.update_solved_labels(hint, 'disabled') self.imgdir = dirname(img) if hint == 'v': self.vimg_fn = img self.vwcs_fn = wcs self.havev = True self.wvar1.configure(text=basename(img)) self.wvfn.configure(bg='green', activebackground='green') elif hint == 'h': self.himg_fn = img self.hwcs_fn = wcs self.haveh = True self.wvar2.configure(text=basename(img)) self.whfn.configure(bg='green', activebackground='green') elif hint == 'i': self.iimg_fn = img self.iwcs_fn = wcs self.havei = True self.wvar3.configure(text=basename(img)) self.wifn.configure(bg='green', activebackground='green')
Example #30
Source File: Skeleton_Key.py From firmware_password_manager with MIT License | 5 votes |
def local_nav_pane(self): """ Select keyfile from local volume. """ self.logger.info("%s: activated" % inspect.stack()[0][3]) self.key_item = tkFileDialog.askopenfilename(title="Local object", message="Select local object:", parent=self.root) if self.key_item: self.status_string.set('Object found.') self.handle_key_item() else: self.status_string.set('No object selected.')