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
python类askopenfilename()的实例源码
def restore_clustering(self):
# A window pops up asking the user to specify the path of a *.ANobj (Analysis Object) file
# and attempts to restore it using the Analysis.restore classmethod. Then opens a ClusteringWindow
# which gives the user the option to plot clusters, save the object, or close the window.
fname = askopenfilename(initialdir=IRIS_CSCRATCH_DIR,
filetypes=(("Analysis File Object", "*.ANobj"), ("All Files", "*.*")))
if fname == "" or fname == (): return None
try:
self.AN = analysis.Analysis.restore(fname)
self._restore_settings_from_loaded_object()
self.root.event_generate("<<clustering_restored>>", when="tail")
self.using_analysis_var.set("Using analysis object from\n{}".format(jt.break_path(fname, 24)))
self.using_analysis_label.config(fg="dark green")
except:
ErrorWindow(self.root, "Incorrect file format.")
return None
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)
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
def load_event_seq_file():
global FILE_NAME, EVENT_SEQ
import tkFileDialog
FILE_NAME = tkFileDialog.askopenfilename(
filetypes=[("Event sequence file", ".txt")])
try:
file = open(FILE_NAME, "r")
contents = file.read()
file.close()
print "Here are the contents of the event sequence file as read in: "
print contents
lines = contents.split("\n")
except:
print "Could not load new data from file: ", FILE_NAME
return
# Parse the contents:
EVENT_SEQ = lines
#print "EVENT_SEQ = "+str(EVENT_SEQ)
def press(button):
if button == "Browse":
global videoFile
videoFile = tkFileDialog.askopenfilename()
pathwin.setEntry("Path", videoFile)
elif button == "Submit":
global seconds
seconds = int(pathwin.getEntry("Seconds"))
pathwin.stop()
def askopenfilename(self):
"""Returns a file name """
filename = tkFileDialog.askopenfilename(**self.file_opt)
if filename:
return filename
def getIdentityFile(self):
r = tkFileDialog.askopenfilename()
if r:
self.identity.delete(0, Tkinter.END)
self.identity.insert(Tkinter.END, r)
def file_dialog(*args, **kargs):
import sys
if sys.version_info[0] <= 2:
import tkFileDialog, Tkinter
else:
import tkinter as Tkinter
from tkinter import filedialog as tkFileDialog
f = Tkinter.Tk()
f.withdraw()
ret = tkFileDialog.askopenfilename(*args, **kargs)
f.destroy()
return ret
prova_gui.py 文件源码
项目:software-suite-movie-market-analysis
作者: 93lorenzo
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def mainPredSet(init):
filename = fd.askopenfilename()
root = Tk()
init.destroy()
Label(root,text = " Testing data from file... ").pack(padx= 20,pady=20)
root.wm_minsize(width=150, height=150)
fetchPredSet(filename,root)
def _open_file(self, *args):
self.infile = "'%s'" % tkFileDialog.askopenfilename() # quote name in case of whitespace
if args[0] in self.arg_info:
self.arg_value[args[0]].set(self.infile.strip('\''))
self.arg_info[args[0]].set("[%s]" % self.infile.split('/')[-1].strip('\''))
def openFile(self):
self.db_entry.delete(0,tk.END)
ftypes=[('sqlite files','*.sqlite'),('ALL files','*')]
filename=askopenfilename(filetypes=ftypes)
self.db_entry.insert(tk.END,filename)
if len(filename)>0:
#print('Database file: %s' %filename)
printch('?:')
print(' '+filename)
self.probeAlbums()
def _run_selectfile(self):
filename = tkFileDialog.askopenfilename(**dict(
filetypes=[('All files', '.*'), ('Python', '.py')],
title='Select file'))
self._attachfile_text.set(filename)
if filename:
self._btn_runedit.config(state=tk.NORMAL)
print(filename)
def ask_open_filename(self):
return filedialog.askopenfilename()
def ask_open_filename(self):
return filedialog.askopenfilename()
def BrowseButtonClickGPA(self):
"""
Browse button for gene presence absence field
"""
myfile = \
tkFileDialog.askopenfilename(
filetypes=[('comma-separated values', '.csv'),
('all files','.*')])
self.GPAentryVariable.set(myfile)
def BrowseButtonClickTraits(self):
"""
Browse button for traits field
"""
myfile = \
tkFileDialog.askopenfilename(
filetypes=[('comma-separated values', '.csv'),
('all files','.*')])
self.TraitsentryVariable.set(myfile)
def BrowseButtonClickTreeFile(self):
"""
Browse button for tree field
"""
myfile = \
tkFileDialog.askopenfilename(
filetypes=[('newick tree files', '.nwk'),
('all files','.*')])
self.TreeentryVariable.set(myfile)
def BrowseButtonClickRestrict(self):
"""
Browse button for isolate restriction field
"""
myfile = \
tkFileDialog.askopenfilename(
filetypes=[('comma-separated values','.csv'),
('all files','.*')])
self.RestrictVariable.set(myfile)
def launch_analysis():
global popups
filename = tkFileDialog.askopenfilename(parent=app,title='Choose a file',filetypes = [('sgf', '.sgf')])
log(filename)
log("gamename:",filename[:-4])
if not filename:
return
log("filename:",filename)
top = Toplevel()
bots=[]
Config = ConfigParser.ConfigParser()
Config.read(config_file)
if Config.get("Leela","Command")!="":
bots.append(("Leela",leela_analysis.RunAnalysis))
if Config.get("AQ","Command")!="":
bots.append(("AQ",aq_analysis.RunAnalysis))
if Config.get("Ray","Command")!="":
bots.append(("Ray",ray_analysis.RunAnalysis))
if Config.get("GnuGo","Command")!="":
bots.append(("GnuGo",gnugo_analysis.RunAnalysis))
new_popup=RangeSelector(top,filename,bots=bots)
new_popup.pack()
popups.append(new_popup)
top.mainloop()