本文整理汇总了Python中tkFileDialog.askopenfilename函数的典型用法代码示例。如果您正苦于以下问题:Python askopenfilename函数的具体用法?Python askopenfilename怎么用?Python askopenfilename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了askopenfilename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: browse_command
def browse_command(self, source):
if source == 0:
# Get the spec file location
self.spec_file = tkFileDialog.askopenfilename(multiple=False,
initialdir=self.default_path,
filetypes=[("SUMA spec file", "*.spec")])
if self.spec_file:
self.spec_var.set(self.spec_file)
self.default_path = os.path.dirname(self.spec_file)
elif source == 1:
# Get the volume file location
self.vol_file = tkFileDialog.askopenfilename(multiple=False,
initialdir=self.default_path,
filetypes=[("AFNI HEAD file", "*.HEAD"),])
if self.vol_file:
self.vol_var.set(self.vol_file)
self.default_path = os.path.dirname(self.vol_file)
# ("AFNI BRIK file", "*.BRIK")])
# Remove the file extension
# self.vol_file = os.path.splitext(self.vol_file)[0]
elif source == 2:
# Get the annot file location
self.annot_file = tkFileDialog.askopenfilename(multiple=False,
initialdir=self.default_path,
filetypes=[("FreeSurfer annot file", "*.annot")])
if self.annot_file:
self.annot_var.set(self.annot_file)
self.default_path = os.path.dirname(self.annot_file)
示例2: engage
def engage(self, hideOrNot, extension):
hidey = hideOrNot.get()
ext = extension.get()
if hidey == 0:
imageFile = tkFileDialog.askopenfilename(title="Hiding: Choose Image File") # Get the image file from the user
dataFile = tkFileDialog.askopenfilename(title="Hiding: Choose Data File") # Get the data file from the user
errorCode = HerpHandler(hidey, imageFile, ext, dataFile) # Handle Operational Errors
if errorCode == 1:
tkMessageBox.showerror("Error", "The image does not match the chosen image type!")
elif errorCode == 2:
tkMessageBox.showerror("Error", "Too much data to fit")
elif errorCode == 3:
tkMessageBox.showerror("Error", "IOError: Could not open data file or image")
elif errorCode == 4:
tkMessageBox.showerror("Error", "IOError: Could not write to file")
elif errorCode == 5:
tkMessageBox.showerror("Error", "Out of Bounds Error")
else:
tkMessageBox.showinfo("Operation Complete", "Hiding Complete")
else:
imageFile = tkFileDialog.askopenfilename(title="Retrieving: Choose Image File") # Get the image file from the user
errorCode = HerpHandler(hidey, imageFile, ext, None) # Handle Operational Errors
if errorCode == 1:
tkMessageBox.showerror("Error", "The image does not match the chosen image type!")
elif errorCode == 2:
tkMessageBox.showerror("Error", "Too much data to fit")
elif errorCode == 3:
tkMessageBox.showerror("Error", "IOError: Could not open data file or image")
elif errorCode == 4:
tkMessageBox.showerror("Error", "IOError: Could not write to file")
elif errorCode == 5:
tkMessageBox.showerror("Error", "Out of Bounds Error")
else:
tkMessageBox.showinfo("Operation Complete","Retrieval Complete")
示例3: open_list
def open_list(self):
"""
opens a saved playlist
playlists are stored as textfiles each record being "path","title"
"""
if self.options.initial_playlist_dir=='':
self.filename.set(tkFileDialog.askopenfilename(defaultextension = ".csv",
filetypes = [('csv files', '.csv')],
multiple=False))
else:
self.filename.set(tkFileDialog.askopenfilename(initialdir=self.options.initial_playlist_dir,
defaultextension = ".csv",
filetypes = [('csv files', '.csv')],
multiple=False))
filename = self.filename.get()
if filename=="":
return
self.options.initial_playlist_dir = ''
ifile = open(filename, 'rb')
pl=csv.reader(ifile)
self.playlist.clear()
self.track_titles_display.delete(0,self.track_titles_display.size())
for pl_row in pl:
if len(pl_row) != 0:
self.playlist.append([pl_row[0],pl_row[1],'',''])
self.track_titles_display.insert(END, pl_row[1])
ifile.close()
self.playlist.select(0)
self.display_selected_track(0)
return
示例4: FindFile
def FindFile(self):
oldfile = self.value
if self.action == "open":
if self.filetypes:
browsevalue=tkFileDialog.askopenfilename(initialfile=self.value,
filetypes=self.filetypes)
self.browsevalue=str(browsevalue)
else:
browsevalue=tkFileDialog.askopenfilename(initialfile=self.value)
self.browsevalue=str(browsevalue)
else: # elif self.action == "save":
if self.filetypes:
browsevalue=tkFileDialog.asksaveasfilename(initialfile=self.value,
filetypes=self.filetypes)
self.browsevalue=str(browsevalue)
else:
browsevalue=tkFileDialog.asksaveasfilename(initialfile=self.value)
self.browsevalue=str(browsevalue)
if len(self.browsevalue) == 0:
self.browsevalue = oldfile
if self.command:
#self.command()
# We pass browsevalue through, although the previous binding means that
# the command must also be capable of receiving a Tkinter event.
# See the interfaces/dalton.py __update_script method
self.command( self.browsevalue )
self.entry.setvalue(self.browsevalue)
self.editor.calc.set_parameter(self.parameter,self.browsevalue)
else:
self.entry.setvalue(self.browsevalue)
self.editor.calc.set_parameter(self.parameter,self.browsevalue)
示例5: go
def go():
window = Tkinter.Tk()
window.withdraw()
window.wm_title("tk-okienko")
mg.vid1 = VideoCapture(tkFileDialog.askopenfilename(title="Wybierz wideo zewnętrzne", filetypes=mg.videoTypes))
mg.vid1LastFrame = mg.vid1.read()[1]
mg.vid1LastFrameClean = numpy.copy(mg.vid1LastFrame)
mg.vid2 = VideoCapture(tkFileDialog.askopenfilename(title="Wybierz wideo wewnętrzne", filetypes=mg.videoTypes))
namedWindow(mg.imgWindowName)
setPoints(True)
setMouseCallback(mg.imgWindowName, onMouseClick)
imshow(mg.imgWindowName, mg.vid1LastFrame)
waitKey(0)
setMouseCallback(mg.imgWindowName, lambda a1, a2, a3, a4, a5: None)
while True:
innerFrame = mg.vid2.read()[1]
fillPoly(mg.vid1LastFrameClean, numpy.array([[mg.p1, mg.p2, mg.p4, mg.p3]]), (0,0,0))
imshow("video", mg.vid1LastFrameClean+getTransformed(innerFrame))
mg.previousFrameClean = mg.vid1LastFrameClean
ret, mg.vid1LastFrame = mg.vid1.read()
mg.vid1LastFrameClean = numpy.copy(mg.vid1LastFrame)
corners()
if not ret:
break
key = waitKey(30)
if key%256 == 27:
break
示例6: openSTLFile
def openSTLFile(self):
if self.printing:
self.logger.logMsg("Cannot open a new file while printing")
return
if self.StlFile is None:
fn = askopenfilename(
filetypes=[("STL files", "*.stl"), ("G Code files", "*.gcode")], initialdir=self.settings.lastdirectory
)
else:
fn = askopenfilename(
filetypes=[("STL files", "*.stl"), ("G Code files", "*.gcode")],
initialdir=self.settings.lastdirectory,
initialfile=os.path.basename(self.StlFile),
)
if fn:
self.settings.lastdirectory = os.path.dirname(os.path.abspath(fn))
self.settings.setModified()
if fn.lower().endswith(".gcode"):
self.StlFile = None
self.loadgcode(fn)
elif fn.lower().endswith(".stl"):
self.StlFile = fn
self.doSlice(fn)
else:
self.logger.logMsg("Invalid file type")
示例7: CMVDialog
def CMVDialog(self):
import tkFileDialog
import tkMessageBox
try:
import pygame as pg
except ImportError:
tkMessageBox.showerror('Error', 'This plugin requires the "pygame" module')
return
myFormats = [('Portable Network Graphics', '*.png'), ('JPEG / JFIF', '*.jpg')]
try:
image_file = tkFileDialog.askopenfilename(parent=self.root,
filetypes=myFormats, title='Choose the contact map image file')
if not image_file:
raise
except:
tkMessageBox.showerror('Error', 'No Contact Map!')
return
myFormatsPDB = [('Protein Data Bank', '*.pdb'), ('MDL mol', '*.mol'), ('PyMol Session File', '*.pse')]
try:
pdb_file = tkFileDialog.askopenfilename(parent=self.root,
filetypes=myFormatsPDB, title='Choose the corresponding PDB file')
if not pdb_file:
raise
except:
tkMessageBox.showerror('Error', 'No PDB file!')
return
name = cmd.get_unused_name('protein')
cmd.load(pdb_file, name)
contact_map_visualizer(image_file, name, 1, 0)
示例8: de
def de():
print "Select the encrypted file"
Tk().withdraw()
path_of_file_data_in_ = askopenfilename()
path_of_de_data_in = open(path_of_file_data_in_, "r")
de_data_in = path_of_de_data_in.read()
path_of_de_data_in.close()
print "Select the key"
path_of_file_data_key_ = askopenfilename()
path_of_de_key = open(path_of_file_data_key_, "r")
de_key_in = path_of_de_key.read()
path_of_de_key.close()
de_xor_x = xor_en(de_data_in, ke=de_key_in)
path_of_de_data_out = open("de/de_data.out", "w")
path_of_de_data_out.write(de_xor_x)
path_of_de_data_out.close()
log_header_de= """Date: """ + str(now) + """
Encrypted Message: """ + str(de_data_in) + """
Key:"""+str(de_key_in)+"""
Decrypted Message: """+ str(de_xor_x)+ """\n"""
log_de = 'de/log.txt'
log_data_de = open(log_de, "w")
log_data_de.write(log_header_de + "\n" )
log_data_de.close()
os.system("gedit de/log.txt de/de_data.out")
示例9: _openDialog
def _openDialog(self):
fpath = os.path.join( wtsettings.pathRes, self.entry.get())
fpath = os.path.abspath(fpath)
dirname = os.path.dirname(fpath)
dirname = os.path.abspath(dirname)
# print "dirname",[dirname]
newpath = ""
if os.path.isfile(fpath):
# print "isfile",[fpath]
newpath = tkFileDialog.askopenfilename(initialfile= fpath, filetypes = self.ftypes)
elif os.path.isdir(dirname):
newpath =tkFileDialog.askopenfilename(initialdir= dirname, filetypes = self.ftypes)
# print "isdir"
else:
newpath =tkFileDialog.askopenfilename(initialdir= wtsettings.pathRes, filetypes = self.ftypes)
# print "no isdir"
if newpath:
num2res = len(os.path.normpath(os.path.abspath(wtsettings.pathRes)).split(os.path.sep))
newpath = os.path.normpath(newpath).split(os.path.sep)
newpath = os.path.join( *newpath[num2res:] )
newpath = newpath.replace("\\","/")
self.entry.delete(0, END)
self.entry.insert(0, newpath)
if self.old_value != newpath:
self.onValueChangeEndByUser(self.old_value, newpath)
self._updateImage()
示例10: SelectFile
def SelectFile(self, parent, defaultextension=None):
if len(self.preferences.workSpaceFolder) > 0:
return askopenfilename(
parent=parent, initialdir=self.preferences.workSpaceFolder, defaultextension=defaultextension
)
else:
return askopenfilename(parent=parent, defaultextension=defaultextension)
示例11: calibrate
def calibrate(poni_file=None, calibration_imagefile=None, dspace_file=None,
wavelength=None, detector=None):
"""
Load the calibration file/make a calibration file
"""
pwd = os.getcwd()
if poni_file is None:
print 'Open PONI'
poni_file = tkFileDialog.askopenfilename(defaultextension='.poni')
if poni_file == '':
# if prompt fail run calibration via pyFAI
if calibration_imagefile is None:
calibration_imagefile = tkFileDialog.askopenfilename(
defaultextension='.tif')
if dspace_file is None:
dspace_file = tkFileDialog.askopenfilename()
detector = detector if detector is not None else raw_input(
'Detector Name: ')
wavelength = wavelength if wavelength is not None else raw_input(
'Wavelength in Angstroms: ')
calibration_image_dir, calibration_image_name = os.path.split(
calibration_imagefile)
os.chdir(calibration_image_dir)
subprocess.call(['pyFAI-calib',
'-w', str(wavelength),
'-D', str(detector),
'-S', str(dspace_file),
str(calibration_image_name)])
# get poni_file name make new poni_file
poni_file = os.path.splitext(calibration_imagefile)[0] + '.poni'
os.chdir(pwd)
a = loadgeometry(poni_file)
return a
示例12: load_ImageOnclicked
def load_ImageOnclicked(self):
###########################################################################
## Displaying input image.
###########################################################################
global initial_im
global ref
global initial_depth
ImageName = askopenfilename(initialdir="F:\UWA\GENG5511\simulation\images",title = "Choose an image file.")
#Using try in case user types in unknown file or closes without choosing a file.
try:
with open(ImageName,'r') as UseFile:
print (ImageName)
except:
print("No file exists")
DepthName = askopenfilename(initialdir="F:\UWA\GENG5511\simulation\images")
#Using try in case user types in unknown file or closes without choosing a file.
try:
with open(DepthName,'r') as UseFile:
print (DepthName)
except:
print("No file exists")
ref,initial_im=load_Image(ImageName)
initial_depth=load_Depth(DepthName,ref,initial_im)
示例13: Operations
def Operations(self, optionChoice):
# File operations - calls to other modules to be implemented here
# *************** file operations and other action calls to be implemented here ***************
#
# FILE OPERATION CALLS
if optionChoice == 1:
foo = None
elif optionChoice == 2:
self.filename = tkFileDialog.askopenfilename(filetypes=[("CSV", "*.csv")])
if self.filename != '':
status_return, color, status_Done, donecolor = BioRad_CSV.main(self.filename, 'duplex')
self.updateStatus(self.master, status_return, 1, 2000, color)
if status_Done != '':
def done_stat():
self.updateStatus(self.master, status_Done, 1, 3000, donecolor)
self.master.after(5000, done_stat)
elif optionChoice == 3:
self.filename = tkFileDialog.askopenfilename(filetypes=[("CSV", "*.csv")])
if self.filename != '':
status_return, color, status_Done, donecolor = BioRad_CSV.main(self.filename, 'singleplex')
self.updateStatus(self.master, status_return, 1, 2000, color)
if status_Done != '':
def done_stat():
self.updateStatus(self.master, status_Done, 1, 3000, donecolor)
self.master.after(5000, done_stat)
else:
print "INTERNAL ERROR: else condition inside Operations"
示例14: addSimulatorPath
def addSimulatorPath( self ):
filename = ""
if platform.system() == "Windows":
filename = tkFileDialog.askopenfilename(parent=self.__root,initialdir="/",defaultextension=".exe",title='Pick a exe')
else:
filename = tkFileDialog.askopenfilename(parent=self.__root,initialdir="/",defaultextension=".app",title='Pick a app')
self.__slVar.set( filename )
self.writeJson( "SimulatorPath", filename )
示例15: _check_browse
def _check_browse(self, index):
if index == 0:
return tkFileDialog.asksaveasfilename(defaultextension = FILES_JPT[0][1], filetypes = FILES_JPT)
if index == 1:
return tkFileDialog.askopenfilename(defaultextension = FILES_JPEG[0][1], filetypes = FILES_JPEG)
if index == 2:
return tkFileDialog.askopenfilename(defaultextension = FILES_PNG[0][1], filetypes = FILES_PNG)
return FrameJpt._check_browse(index)