def openBox(
self,
title=None,
dirName=None,
fileTypes=None,
asFile=False):
self.topLevel.update_idletasks()
# define options for opening
options = {}
if title is not None:
options['title'] = title
if dirName is not None:
options['initialdir'] = dirName
if fileTypes is not None:
options['filetypes'] = fileTypes
if asFile:
return filedialog.askopenfile(mode="r", **options)
# will return "" if cancelled
else:
return filedialog.askopenfilename(**options)
python类askopenfile()的实例源码
def openBox(
self,
title=None,
dirName=None,
fileTypes=None,
asFile=False):
self.topLevel.update_idletasks()
# define options for opening
options = {}
if title is not None:
options['title'] = title
if dirName is not None:
options['initialdir'] = dirName
if fileTypes is not None:
options['filetypes'] = fileTypes
if asFile:
return filedialog.askopenfile(mode="r", **options)
# will return "" if cancelled
else:
return filedialog.askopenfilename(**options)
def openBox(
self,
title=None,
dirName=None,
fileTypes=None,
asFile=False):
self.topLevel.update_idletasks()
# define options for opening
options = {}
if title is not None:
options['title'] = title
if dirName is not None:
options['initialdir'] = dirName
if fileTypes is not None:
options['filetypes'] = fileTypes
if asFile:
return filedialog.askopenfile(mode="r", **options)
# will return "" if cancelled
else:
return filedialog.askopenfilename(**options)
def handle_open_pgn(self):
self.pgn_file = tkFileDialog.askopenfile(mode='r')
if ( self.pgn_file is None ):
return
self.header_list = list()
self.offset_list = list()
self.pgn_item_list = list()
print(self.pgn_file)
for offset,headers in chess.pgn.scan_headers(self.pgn_file):
header_string = ""
for key in headers.keys():
header_string +=str(headers[key]) + " "
header_string +="\n"
self.header_list.append(header_string)
print(headers.keys)
self.offset_list.append(offset)
self.pgn_item_list.append(PgnItem(header_string,offset))
self.pgnDialog = PgnDialog(self,self.pgn_item_list)
def load_config():
config_file = tkFileDialog.askopenfile("r")
# Get parameters from .txt file
[username, password, start_date, end_date, area_of_interest, platform, max_cloud_cover, download_path, image_id, download_options,
image_path, preprocessing_options] = configuration.read_txt(config_file)
# Clear old values
clear_all()
# Set new settings
entries.set(username, password, start_date, end_date, area_of_interest, platform, max_cloud_cover, download_path, download_options,
image_id, image_path, preprocessing_options, textbox_username, textbox_password, textbox_start_date,
textbox_end_date, textbox_aoi, variable_sentinel1, variable_sentinel2, textbox_cloud_cover, textbox_download_path,
textbox_product_id, variable_save_metadata, variable_plot_footprints, variable_download_test_image,
variable_download_all, textbox_image_path, variable_mosaick, variable_subset)
# Method for saving a configuration file
def Get_Load_File(self):
myFormats = [('AutoCAD / QCAD Drawing','*.dxf'),\
('All File','*.*') ]
inidir=self.config.load_path
filename = askopenfile(initialdir=inidir,\
filetypes=myFormats)
if not filename:
return
else:
self.load_filename=filename.name
self.Load_File(self.load_filename)
def Get_Load_File(self):
myFormats = [('AutoCAD / QCAD Drawing','*.dxf'),\
('All File','*.*') ]
inidir=self.config.load_path
filename = askopenfile(initialdir=inidir,\
filetypes=myFormats)
if not filename:
return
else:
self.load_filename=filename.name
self.Load_File(self.load_filename)
def choose_file_dialog(**options):
""" Creates an open file dialog to choose a file, and returns a handle to that file """
root = Tk.Tk()
root.geometry('0x0+400+400')
root.wait_visibility()
root.wm_attributes('-alpha', 0.0)
root.lift()
root.focus_force()
chosen_files = tkFileDialog.askopenfile(**options)
root.destroy()
return chosen_files
def load_file():
global password, filename
text_file = tkFileDialog.askopenfile()
if text_file.name != None:
filename = text_file.name
var.set(filename)
def open_image():
im = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file')
input = open('im','r')
label_image.config = Label(image_tab, image=input)
#print(im)
#im = Image.open(name_image)
def set_external_engine(self):
engine_file=tkFileDialog.askopenfile(mode='r')
if ( engine_file is None):
return
self.enginePath = engine_file.name
try:
self.set_engine_player()
except:
tkMessageBox.showerror("Error", "Could not intialize!")
self.decide_who_plays()
def load_config(self, filename=None):
if filename is None:
file_obj = tkFileDialog.askopenfile()
if file_obj is None: return
else:
file_obj = open(filename, 'r')
try:
load_config(file_obj, self.lens1, self.lens2)
except:
tkMessageBox.showerror('Config load error', traceback.format_exc())
def _file_select(self, tkstr):
result = tkFileDialog.askopenfile()
if result is not None:
tkstr.set(result.name)
result.close()
# Make a combined label/textbox/slider for a given variable: