Python tkinter.filedialog() Examples

The following are 17 code examples of tkinter.filedialog(). 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 tkinter , or try the search function .
Example #1
Source File: gui_02.py    From Modern-Python-Standard-Library-Cookbook with MIT License 8 votes vote down vote up
def dialog(ask, title, message=None, **kwargs):
    for widget in (messagebox, simpledialog, filedialog):
        show = getattr(widget, 'ask{}'.format(ask), None)
        if show:
            break
    else:
        raise ValueError('Unsupported type of dialog: {}'.format(ask))

    options = dict(kwargs, title=title)
    for arg, replacement in dialog.argsmap.get(widget, {}).items():
        options[replacement] = locals()[arg]
    return show(**options) 
Example #2
Source File: components.py    From SEM with MIT License 6 votes vote down vote up
def select_file(self, event=None):
        options = {}
        options['defaultextension'] = '.txt'
        options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
        options['initialdir'] = os.path.join(sem.SEM_DATA_DIR, "resources", "patterns")
        options['parent'] = self.trainTop
        options['title'] = 'Select pattern file.'
        pattern = tkinter.filedialog.askopenfilename(**options)
        self.pattern_label_var.set(pattern) 
Example #3
Source File: Sooty.py    From Sooty with GNU General Public License v3.0 6 votes vote down vote up
def hashAndFileUpload():
    root = tkinter.Tk()
    root.filename = tkinter.filedialog.askopenfilename(initialdir="/", title="Select file")
    hasher = hashlib.md5()
    with open(root.filename, 'rb') as afile:
        buf = afile.read()
        hasher.update(buf)
    fileHash = hasher.hexdigest()
    print(" MD5 Hash: " + fileHash)
    root.destroy()
    apierror = False
    # VT Hash Checker
    url = 'https://www.virustotal.com/vtapi/v2/file/report'

    params = {'apikey': configvars.data['VT_API_KEY'], 'resource': fileHash}
    response = requests.get(url, params=params)

    try:  # EAFP
        result = response.json()
    except:
        apierror = True
        print("Error: Invalid API Key")
    if not apierror:
        if result['response_code'] == 0:
            print("\n Hash was not found in Malware Database")
        elif result['response_code'] == 1:
            print(" VirusTotal Report: " + str(result['positives']) + "/" + str(result['total']) + " detections found")
            print("   Report Link: " + "https://www.virustotal.com/gui/file/" + fileHash + "/detection")
        else:
            print("No Response")
    hashMenu() 
Example #4
Source File: annotation_gui.py    From SEM with MIT License 5 votes vote down vote up
def save_gate(self, event=None):
        output_directory = tkinter.filedialog.askdirectory(initialdir=sem.SEM_DATA_DIR)
        self.save_as_format(output_directory, "gate") 
Example #5
Source File: annotation_gui.py    From SEM with MIT License 5 votes vote down vote up
def save_tei_analec(self, event=None):
        output_directory = tkinter.filedialog.askdirectory(initialdir=sem.SEM_DATA_DIR)
        self.save_as_format(output_directory, "tei_analec") 
Example #6
Source File: annotation_gui.py    From SEM with MIT License 5 votes vote down vote up
def save_json(self, event=None):
        output_directory = tkinter.filedialog.askdirectory(initialdir=sem.SEM_DATA_DIR)
        self.save_as_format(output_directory, "jason")
    
    #
    # Edit menu methods
    # 
Example #7
Source File: annotation_gui.py    From SEM with MIT License 5 votes vote down vote up
def load_tagset_gui(self, event=None):
        filename = tkinter.filedialog.askopenfilename(filetypes=[("text files", ".txt"), ("All files", ".*")], initialdir=os.path.join(sem.SEM_DATA_DIR, "resources", "tagsets"))
        
        if len(filename) == 0: return
        
        self.load_tagset(filename) 
Example #8
Source File: components.py    From SEM with MIT License 5 votes vote down vote up
def filenames(self, event=None):
        self.current_files = list(tkinter.filedialog.askopenfilenames(**self.file_opt))
        self.current_files.sort(key=lambda x:x.lower())
        self.selected_files.delete(0, tkinter.END)
        if self.current_files:
            for current_file in self.current_files:
                self.selected_files.insert(tkinter.END, os.path.basename(current_file))
            self.file_opt['initialdir'] = os.path.dirname(self.current_files[0]) 
Example #9
Source File: annotation_gui.py    From SEM with MIT License 5 votes vote down vote up
def openfile_gui(self, event=None):
        filenames = tkinter.filedialog.askopenfilenames(filetypes=[("SEM readable files", (".txt", ".sem.xml", ".sem", ".ann")), ("text files", ".txt"), ("BRAT files", (".txt", ".ann")), ("SEM XML files", ("*.sem.xml", ".sem")), ("All files", ".*")])
        if filenames == []: return
        self.openfile(filenames) 
Example #10
Source File: cameralink.py    From crappy with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, numdevice=0, config_file=None, camera_type=None):
    """Using the clModule, will open a cameraLink camera.
    If a config file is specified, it will be used to configure the camera
    If not set, it will be asked, unless set to False (or 0)
    Else, you must at least provide the camera type (eg: "FullAreaGray8")
    Using a config file is recommended over changing all settings manually
    """
    #print("config_file:",config_file)
    Camera.__init__(self)
    self.config_file = config_file
    self.camera_type = camera_type
    if config_file is None:
      import tkinter
      import tkinter.filedialog
      root = tkinter.Tk()
      root.withdraw()
      self.config_file = tkinter.filedialog.askopenfilename(parent=root)
      root.destroy()
    if self.camera_type is None and self.config_file:
      with open(self.config_file,'r') as f:
        r = f.readlines()
      r = [s for s in r if s[:5]=="Typ='"]
      if len(r) != 0:
        self.camera_type = r[0][5:-3]
    if self.camera_type is None:
      raise AttributeError("No camera type or valid config file specified!")
    self.name = "cl_camera"
    self.numdevice = numdevice
    self.add_setting("width",setter=self._set_w, getter=self._get_w)
    self.add_setting("height",setter=self._set_h, getter=self._get_h)
    self.add_setting("framespersec",setter=self._set_framespersec,
        getter=self._get_framespersec,limits=(1,200)) 
Example #11
Source File: tmy.py    From pvlib-python with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _interactive_load():
    import tkinter
    from tkinter.filedialog import askopenfilename
    tkinter.Tk().withdraw()  # Start interactive file input
    return askopenfilename() 
Example #12
Source File: gui.py    From synthesizer with GNU Lesser General Public License v3.0 5 votes vote down vote up
def start(self, samples_location: str):
        self.messages.insert(tkinter.END, "~~~~ Python DrumKit ~~~~\n")
        if not os.path.isdir(samples_location):
            print(">>>> Select the directory contaiting the  Salamander Drumkit v1 files <<<<")
            samples_location = tkinter.filedialog.askdirectory()
        import threading
        threading.Thread(target=self.load_drumkit, args=(samples_location,)).start()
        self.mainloop() 
Example #13
Source File: Sooty.py    From Sooty with GNU General Public License v3.0 5 votes vote down vote up
def hashFile():
    root = tkinter.Tk()
    root.filename = tkinter.filedialog.askopenfilename(initialdir="/", title="Select file")
    hasher = hashlib.md5()
    with open(root.filename, 'rb') as afile:
        buf = afile.read()
        hasher.update(buf)
    print(" MD5 Hash: " + hasher.hexdigest())
    root.destroy()
    hashMenu() 
Example #14
Source File: annotation_gui.py    From SEM with MIT License 5 votes vote down vote up
def save_brat(self, event=None):
        output_directory = tkinter.filedialog.askdirectory(initialdir=sem.SEM_DATA_DIR)
        self.save_as_format(output_directory, "brat") 
Example #15
Source File: setup_utils.py    From mmvt with GNU General Public License v3.0 5 votes vote down vote up
def choose_folder_gui(initialdir='', title=''):
    import tkinter
    from tkinter.filedialog import askdirectory
    root = tkinter.Tk()
    root.withdraw()  # hide root
    if initialdir != '':
        fol = askdirectory(initialdir=initialdir, title=title)
    else:
        fol = askdirectory(title=title)
    if is_windows():
        fol = fol.replace('/', '\\')
    return fol 
Example #16
Source File: install_blender_reqs.py    From mmvt with GNU General Public License v3.0 5 votes vote down vote up
def choose_folder_gui(initialdir='', title=''):
    import tkinter
    from tkinter.filedialog import askdirectory
    root = tkinter.Tk()
    root.withdraw()  # hide root
    if initialdir != '':
        fol = askdirectory(initialdir=initialdir, title=title)
    else:
        fol = askdirectory(title=title)
    if is_windows():
        fol = fol.replace('/', '\\')
    return fol 
Example #17
Source File: annotation_gui.py    From SEM with MIT License 5 votes vote down vote up
def save(self, event=None):
        filename = tkinter.filedialog.asksaveasfilename(defaultextension=".sem.xml")
        if filename == u"": return
        
        self.unselect()
        if self.doc_is_modified:
            update_annotations(self.doc, self.annotation_name, self.current_annotations.annotations)
        
        corpus = SEMCorpus(documents=self.corpus_documents)
        with codecs.open(filename, "w", "utf-8") as O:
            corpus.write(O)