def select_file(self): from tkfilebrowser import askopenfilename from tkinter import Tk # Create Tk root root = Tk() # Hide the main window root.withdraw() # Raise the root to the top of all windows. root.call('wm', 'attributes', '.', '-topmost', True) # List of selected filewill be set to self.value ft = self.filetype if ft is not None: if not ft.startswith('.'): ft = '.' + ft name = ft[1:].capitalize() result = askopenfilename( defaultextension=ft, filetypes=[ ('{} file'.format(name),'*{}'.format(ft)), ('All files','*.*')], initialdir=self.initialdir) self.file = result if len(result) > 0 else '' else: result = askopenfilename() self.file = result if len(result) > 0 else '' if len(self.file) > 0: self.description = "File Selected" self.icon = "check-square-o" self.style.button_color = "lightgreen" self.value = True else: self.value = False
def askopenfilename(fd=None, **argv): if fd == None: fd = mode if platform.system() == "Darwin": #load_fd2() return _fd2.askopenfilename(**argv) if fd: return _fd2.askopenfilename(**argv) else: return _fd1.askopenfilename(**argv)
def fgetIcon(self): filename = askopenfilename(parent=self.master, initialdir='/', initialfile='tmp', filetypes=[("All files", "*")], font_size=font_size) self.icon_var.set(filename)
def select_file(self): filename = askopenfilename(self, "Select connection file", initialdir=jupyter_runtime_dir(), defaultextension='.json', filetypes=[('JSON', '*.json'), ('All files', '*')]) if filename: self.entry.delete(0, 'end') self.entry.insert(0, filename)
def take_file(self): file_name = askopenfilename(defaultextension=".png", title='Choose image file', initialdir='C:/Pictures', filetypes=[("All Files", "*.*"), ("PNG", "*.png"), ("JPEG", "*.jpg")]) self.file_name_var.set(file_name)
def fgetTryExec(self): filename = askopenfilename(parent=self.master, initialdir='/', initialfile='tmp', filetypes=[("All files", "*")], font_size=font_size) # if it is in path or not if shutil.which(os.path.basename(filename)): self.tryexec_ent_var.set(os.path.basename(filename)) else: self.tryexec_ent_var.set(filename)
def onClickedLoadQR(self, e): file_path = askopenfilename(initialdir="C:\\", initialfile="tmp", filetypes=[("Pictures", "*.png"), ("All Files", "*")]) print(file_path) self.png = wx.Image(file_path, wx.BITMAP_TYPE_PNG).ConvertToBitmap() self.bitmap = wx.StaticBitmap( self, wx.ID_ANY, self.png, (10, 5), (self.png.GetWidth(), self.png.GetHeight())) self.Update()
def askopenfilename(defaultextension, filetypes, initialdir, initialfile="", title=_('Open'), **options): """ Open filebrowser dialog to select file to open. Arguments: - defaultextension: extension added if none is given - initialdir: directory where the filebrowser is opened - initialfile: initially selected file - filetypes: [('NAME', '*.ext'), ...] """ if tkfb: return tkfb.askopenfilename(title=title, defaultext=defaultextension, filetypes=filetypes, initialdir=initialdir, initialfile=initialfile, **options) elif ZENITY: try: args = [ "zenity", "--file-selection", "--filename", os.path.join(initialdir, initialfile) ] for ext in filetypes: args += ["--file-filter", "%s|%s" % ext] args += ["--title", title] file = check_output(args).decode("utf-8").strip() filename, ext = os.path.splitext(file) if not ext: ext = defaultextension return filename + ext except CalledProcessError: return "" except Exception: return filedialog.askopenfilename( title=title, defaultextension=defaultextension, filetypes=filetypes, initialdir=initialdir, initialfile=initialfile, **options) else: return filedialog.askopenfilename(title=title, defaultextension=defaultextension, filetypes=filetypes, initialdir=initialdir, initialfile=initialfile, **options)
def decode2(): #To decode the data in the image. s1 = tkinter.Tk() sloc = str(askopenfilename()) print('sloc' + sloc) decoded = decode_image(sloc) print(decoded) label2 = tkinter.Label(s1, text='Secret Code:\n' + str(decoded), padx=200, pady=200, bg='black', fg='white') label2.grid(row=0, column=1) s1.mainloop()
def data_handler(delimiter=' '): filename = askopenfilename() # opens file browser to specify file delimiter = ' ' # must match delimiter used in file print('Reading data from file...') tic = time.time() try: data = np.genfromtxt(filename, comments = '#', delimiter=delimiter, unpack = True, encoding=None, names=True, dtype=None) # read data arguments = np.asarray(data.dtype.names, dtype=str) # read header data = np.genfromtxt(filename, comments = '#', delimiter=delimiter, unpack = True) # read data toc = time.time() exc_time = toc - tic print('...finished in ', exc_time, 'seconds.') except: print('Reading data from file failed.') return data, arguments
def findLandmarks(manualWindow, pathClearMap): """ This function is called when the user has to select where the landmarks.csv file is located. :param rootMA: This the window where the select landmarks button is called from. :param pathClearMap: The path to where the entire program is saved. :return: """ landmarksDir = askopenfilename(parent=manualWindow, title="Select landmarks file") print(landmarksDir) pathOutput = pathClearMap + "ClearMap/clearmap_preset_folder/output/landmarks.csv" try: shutil.copyfile(landmarksDir, pathOutput) write_landmarks_to_files(pathClearMap) except FileNotFoundError: kill(pathClearMap)
def cargar_imagen(): global image1, img1, path path = tkfilebrowser.askopenfilename(initialdir="/", title="Select file", filetypes=[("png", "* .png"), ("jpeg", "* .jpg"), ("all files", "*")]) image1 = cv2.imread(path) image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2RGB) img1 = image1 image1 = Image.fromarray(image1).resize((500, 480)) image1 = ImageTk.PhotoImage(image1) show = tkinter.Label(image=image1) show.image = image1 show.place(x=150, y=0)
def askopenfilename(defaultextension, filetypes, initialdir, initialfile="", title=_('Open'), **options): """ plateform specific file browser: - defaultextension: extension added if none is given - initialdir: directory where the filebrowser is opened - filetypes: [('NOM', '*.ext'), ...] """ if tkfb: return tkfb.askopenfilename(title=title, defaultext=defaultextension, filetypes=filetypes, initialdir=initialdir, initialfile=initialfile, **options) elif ZENITY: try: args = ["zenity", "--file-selection", "--filename", os.path.join(initialdir, initialfile)] for ext in filetypes: args += ["--file-filter", "%s|%s" % ext] args += ["--title", title] file = check_output(args).decode("utf-8").strip() filename, ext = os.path.splitext(file) if not ext: ext = defaultextension return filename + ext except CalledProcessError: return "" except Exception: return filedialog.askopenfilename(title=title, defaultextension=defaultextension, filetypes=filetypes, initialdir=initialdir, initialfile=initialfile, **options) else: return filedialog.askopenfilename(title=title, defaultextension=defaultextension, filetypes=filetypes, initialdir=initialdir, initialfile=initialfile, **options)
def cel_detection(importCelWindow, pathClearMap): """ This function is called when the user chooses to import their own cel detection. It opens the file and checks if arivis headers are present. If they aren't the program assumes the csv files first 3 columns are the x y z coordinates without headers. Every time when loading a npy fix imports has to be true because the clearmap program uses a python 2.x way to read the numpy arrays and this fixes any header issues that would otherwise occur. :param importCelWindow: This is the toplevel from where the chooser is called and is used as parent for the file chooser :param pathClearMap: This is the path of the gui. :return: """ cellsDir = askopenfilename( parent=importCelWindow, title="Select the csv file with the detected cells") try: f = open(cellsDir, 'r') reader = csv.reader(f) headers = next(reader, None) column = {} for h in headers: column[h] = [] for row in reader: for h, v in zip(headers, row): column[h].append(v) f.close() if '"X (px), Center of Geometry"' in column and '"Mean, Intensities #1"' in column: #if this is true then it is most likely an exported file from arivis. If it isn't but these columns still #exist then the outcome should be the same. arivis_cel_detection(pathClearMap, column) else: cel_detection_without_int(pathClearMap, cellsDir) except Exception as e: print(e) kill(pathClearMap)
def OpenFile(self): global data temp = askopenfilename() if len(temp) != 0: data = temp self.Image()
def encode_enc(msg): s2 = tkinter.Tk() name = askopenfilename() print(name) global newimg if len(msg) == 0: s9 = tkinter.Tk() label9 = tkinter.Label(s9, text='Data is empty', padx=200, pady=10, bg='black', fg='white') label9.grid(row=1, column=0) def restart(): s9.destroy() s = tkinter.Tk() label2 = tkinter.Label(s, text='STEGANOGRAPHY Using LSB', padx=200, pady=5) label2.grid(row=0, column=0) button2 = tkinter.Button(s, text='Encode', command=encode2, padx=200, pady=5, bg='black', fg='white') button2.grid(row=1, column=0, padx=25, pady=25) button2 = tkinter.Button(s, text='Decode', command=decode2, padx=200, pady=5, bg='black', fg='white') button2.grid(row=2, column=0, padx=25, pady=25) button10 = tkinter.Button(s9, text='Retry', command=restart, padx=200, pady=5, bg='black', fg='white') button10.grid(row=3, column=0, padx=25, pady=25) raise ValueError('Data is empty') def call2(): location = filedialog.askdirectory() print(location) location += '/' create_image(msg, name, location + 'secret-image.png') # decoded = decode_image('secret-image.png') # print(decoded) s2.destroy() s3 = tkinter.Tk() label5 = tkinter.Label(s3, text='Data Encoded', padx=10, pady=10) label5.grid(row=0, column=1) button8 = tkinter.Button(s3, text='Decode', pady=10, command=decode2, padx=10, bg='black', fg='white') button8.grid(row=3, column=1, pady=10, padx=10) button4 = tkinter.Button(s3, text='Quit', pady=10, padx=10, command=s3.destroy, bg='black', fg='white') button4.grid(row=2, column=1, pady=10, padx=10) s3.mainloop() s2 = tkinter.Tk() button3 = tkinter.Button(s2, text='Save as new file', pady=10, command=call2, padx=10, bg='black', fg='white') button3.grid(row=0, column=1, padx=200, pady=200) s2.mainloop()
from selenium import webdriver browser = webdriver.Chrome(executable_path='/chromedriver') browser.maximize_window() tablon = input("Inserta el tablon donde quieres hacer el post. Ex: /mu/: ") browser.get('http://www.hispachan.org' + tablon) #Entra en la pagina de Hispachan junto al tablon donde quieres hacer tu post titulo = browser.find_element_by_name('subject') #Busca el elemento titulo del post y almacena la forma de acceder a el en titulo post = browser.find_element_by_name('message') #Busca el elemento post del post y almacena la forma de acceder a el en post tkinter.Tk().withdraw() imagenI = askopenfilename() while true: if imagenI: imagen = browser.find_element_by_name("imagefile").send_keys(imagenI) break else: print("Por favor, inserte bien el archivo") #Busca el elemento seleccionar archivo del post y abre un dialogo Tkinter para seleccionar el archivo que quieras# input_ = input("Inserta el titulo del post: ") titulo.send_keys(input_) #Le envia el titulo que insertes input_ = input("Inserta el post: ") post.send_keys(input_) #Le envia el post que insertes
from tkfilebrowser import askopenfilename import string import json import csv from sklearn.feature_extraction.text import CountVectorizer file_object = open(askopenfilename(), 'r') test_string = file_object.read() file = open('testfile.txt','w') text = file vectorizer = CountVectorizer() x= vectorizer.fit_transform(text) z= vectorizer.get_feature_names() print(z) print('\n',x.toarray())
# import required modules import numpy as np from tkfilebrowser import askopenfilename # GUI file browser import matplotlib.pyplot as plt import matplotlib filename = askopenfilename() # delimiter = ' ' # must match delimiter used in file #____________________________________________________________________________________________________________________________________________ data = np.genfromtxt(filename, comments='#', delimiter=delimiter, unpack=True, encoding=None, names=True, dtype=None) # read data arguments = np.asarray(data.dtype.names, dtype=str) # read header data = np.genfromtxt(filename, comments='#', delimiter=delimiter, unpack=True) # read data # returns the index of a given keyword, keyword is a string def keyword_index(arguments, keyword): index_keyword = np.where( arguments == keyword) # find index of keyword in arguments array return index_keyword # takes multidimensional array and sorts it for a given keyword
# load h5 files import h5py import numpy as np import time from tkfilebrowser import askopenfilename # GUI file browser #______________________________________________________________________________________________________________________________________________ # Tk().withdraw() # omits empty window filepath = askopenfilename() #'data.h5' tic = time.time() f = h5py.File(filepath, 'r') # creates a file object f and opens it in read mode all_runs = f['All Runs'] # extract all runs struct cam = f['GuppyFl'] # extract camera struct for Guppy fluorescnece # cam = f['Andor'] # cam = f['ADC1'] datasetname = 'image' dataset_ending = '.dat' delimiter = ' ' #______________________________________________________________________________________________________________________________________________ def extraction(save_attribute_file=True): # number of runs NumberOfRuns = len(all_runs.keys()) print('This file contains %s runs.' % NumberOfRuns)
def open_file(): global video_path rep = tkfilebrowser.askopenfilename(initialdir='/', initialfile='tmp',filetypes=[("Videos", "*.mp4")]) video_path.append(rep)