python类asksaveasfilename()的实例源码

codegui.py 文件源码 项目:dayworkspace 作者: copie 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def downfile(self):
        try:
            # ??????????????_???????????
            filename = filedialog.asksaveasfilename()
            self.lfc_field_1_t.delete('0.0', 'end')
            self.lfc_field_1_t.insert('0.0', "??????......\n")

            filename = filename + '.' + \
                requests.get("http://" + HOST + ":" +
                             PORT + "/downfiletype").text

            self.lfc_field_1_t.insert('0.0', "?????????......")

            req = requests.get("http://" + HOST + ":" + PORT + "/downfile")
            if req.status_code == 200:
                with open(filename, 'wb') as savefile:
                    savefile.write(req.content)
                messagebox.showinfo("??", "????")
            else:
                messagebox.showinfo("??", "????????")
        except:
            messagebox.showinfo("??", "????????")
        finally:
            self.lfc_field_1_t.delete('0.0', 'end')
RGBSensor.py 文件源码 项目:coliform-project 作者: uprm-research-resto 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def saveData(red=0, green=0, blue=0, clear=0, lux='0', colortemp='0'):  # function used to save data taken by the sensor
    filename = filedialog.asksaveasfilename(filetypes=[('Text File', '*.txt')])  # asks for save file locatoin
    if os.path.isfile(filename):  # checks if file exists
        os.remove(filename)  # if it exists it is removed.
    file = open(filename, 'a+')  # creates new file
    # writes to new file all data from sensor
    file.write(','.join(['Red: ' + str(red), 'Green: ' + str(green), 'Blue: ' + str(blue), 'Clear:' + str(clear),
                         'Luminosity: ' + lux, 'Color Temperature: ' + colortemp]))
    file.close()  # closes file created

    # Enable interrupts and put the chip back to low power sleep/disabled.
tkdialog.py 文件源码 项目:sc8pr 作者: dmaccarthy 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, response=str, text="", title=None, accept=0, **options):
        if response is bool:
            self.dialog = [askyesno, askokcancel, askretrycancel][accept]
        else: self.dialog = {None:showinfo, str:askstring, int:askinteger, float:askfloat,
            0:askopenfilename, 1:asksaveasfilename, 2:askdirectory}[response]
        self.options = options.copy()
        if "initialdir" in options:
            self.options["initialdir"] = abspath(options["initialdir"])
        if type(response) is int:
            self.args = tuple()
            if title: self.options["title"] = title
        else:
            if title is None:
                title = "Info" if response is None else "Confirm" if response is bool else "Input"
            self.args = title, text
recipe-578569.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def onSave(self):
        filename = asksaveasfilename(defaultextension='.txt',
                                     filetypes=(('Text files', '*.txt'),
                                                ('Python files', '*.py *.pyw'),
                                                ('All files', '*.*')))
        if filename:
            with open(filename, 'w') as stream:
                stream.write(self.gettext())
merac-o-matic-gui.py 文件源码 项目:merac-o-matic 作者: RogueAI42 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def browseForFile(TkStringVar):
    TkStringVar.set(tkFileDialog.asksaveasfilename())

# Tkinter doesn't let you send arguments to functions, so we must make wrapper functions:
tkinter_windows.py 文件源码 项目:Physics-2.0 作者: rschwa6308 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def save_as(self):
        save_object = Save(self)
        filename = filedialog.asksaveasfilename(defaultextension=".sim",
                                                filetypes=(("Simulation file", "*.sim"), ("All files", "*.*")))
        if filename:
            self.filename = filename
            self.name.set(os.path.split(filename)[-1])
            save_object.save_as(filename)
plot.py 文件源码 项目:tadtool 作者: vaquerizaslab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def on_click_save_tads(self, event):
        tk.Tk().withdraw()  # Close the root window
        save_path = filedialog.asksaveasfilename()
        if save_path is not None:
            with open(save_path, 'w') as o:
                for region in self.tad_regions:
                    o.write("%s\t%d\t%d\n" % (region.chromosome, region.start-1, region.end))
plot.py 文件源码 项目:tadtool 作者: vaquerizaslab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def on_click_save_vector(self, event):
        tk.Tk().withdraw()  # Close the root window
        save_path = filedialog.asksaveasfilename()
        if save_path is not None:
            da_sub = self.da[self.current_da_ix]
            with open(save_path, 'w') as o:
                for i, region in enumerate(self.regions):
                    o.write("%s\t%d\t%d\t.\t%e\n" % (region.chromosome, region.start-1, region.end, da_sub[i]))
plot.py 文件源码 项目:tadtool 作者: vaquerizaslab 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def on_click_save_matrix(self, event):
        tk.Tk().withdraw()  # Close the root window
        save_path = filedialog.asksaveasfilename()
        if save_path is not None:
            with open(save_path, 'w') as o:
                # write regions
                for i, region in enumerate(self.regions):
                    o.write("%s:%d-%d" % (region.chromosome, region.start-1, region.end))
                    if i < len(self.regions)-1:
                        o.write("\t")
                    else:
                        o.write("\n")

                # write matrix
                n_rows = self.da.shape[0]
                n_cols = self.da.shape[1]
                for i in range(n_rows):
                    window_size = self.ws[i]
                    o.write("%d\t" % window_size)

                    for j in range(n_cols):
                        o.write("%e" % self.da[i, j])
                        if j < n_cols-1:
                            o.write("\t")
                        else:
                            o.write("\n")
rollingshutter.py 文件源码 项目:rollingshutterpy 作者: alexd3rsan 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def select_output(self) -> None:
        path = asksaveasfilename(title='Please select the path of the image to create.',
                                 defaultextension='.png',
                                 filetypes=[('PNG File', '*.png'), ('JPEG File', '*.jpg')])
        if not path:
            return None

        self.file_output = path

        self.speed_scale.state(['!disabled'])
        self.btn_start['state'] = 'normal'
telematics.py 文件源码 项目:ets2-telemetry-client-python 作者: roundowl 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def saveFile(self):
    self.settings['lastFile'] = filedialog.asksaveasfilename(filetypes=[('JSON file', '.json'), ('All files', '*')], initialfile=self.settings['lastFile'])
    id = os.path.basename(self.settings['lastFile'])
    id = id.split('.')[0]
    # Return if file name was not chosen (user closed the dialog)
    if (len(id) < 1):
      return
    with open(os.path.join(os.getcwd(), 'settings.json'), mode='w') as file:
      file.write(json.dumps(self.settings))
    try:
      with open(os.path.join(os.getcwd(), 'data', (str(id).lower() + '.json')), mode='w') as file:
        file.write(json.dumps(self.output))
    except:
      return
    if (not (id in self.accountlist)):
      self.accountlist[id] = dict()
    try:
      with open(os.path.join(os.getcwd(), 'data', (str(id).lower() + '.0.json')), mode='r') as file:
        self.accountlist[id]['start'] = json.loads(file.read())['timestamp']
    except:
      with open(os.path.join(os.getcwd(), 'data', (str(id).lower() + '.0.json')), mode='w') as file:
        self.output['timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d<br>%H:%M:%S")
        file.write(json.dumps(self.output))
        self.accountlist[id]['start'] = self.output['timestamp']
    self.accountlist[id]['id'] = id
    self.accountlist[id]['filename'] = self.settings['lastFile']
    self.accountlist[id]['stop'] = self.output['timestamp']
    try:
      self.accountlist[id]['odometer'] = self.data.current['truck']['odometer']
    except:
      self.accountlist[id]['odometer'] = 0
    self.accountlist[id]['distance'] = self.output['totalDistanceDriven']
    self.accountlist[id]['totalFuel'] = self.output['fuelUsed']
    self.accountlist[id]['averageFuel'] = self.output['averageFuelConsumption']
    self.accountlist[id]['averageSpeed'] = self.output['averageSpeed']
    self.accountlist[id]['rating'] = 'N/A' #TODO: Make rating system
    with open(os.path.join(os.getcwd(), 'data', ('accountlist.json')), mode='w') as file:
      file.write(json.dumps(self.accountlist))
TSEBIPythonInterface.py 文件源码 项目:pyTSEB 作者: hectornieto 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _get_output_filename(self, title='Select Output File'):
        root, _, asksaveasfilename = self._setup_tkinter()
        # show an "Open" dialog box and return the path to the selected file
        output_file = asksaveasfilename(title=title)
        root.destroy()  # Destroy the GUI
        return output_file
TSEBIPythonInterface.py 文件源码 项目:pyTSEB 作者: hectornieto 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _setup_tkinter(self):
        '''Creates a Tkinter input file dialog'''

        # Import Tkinter GUI widgets
        if sys.version_info.major == 2:
            from tkFileDialog import askopenfilename, asksaveasfilename
            import Tkinter as tk
        else:
            from tkinter.filedialog import askopenfilename, asksaveasfilename
            import tkinter as tk

        # Code below is to make sure the file dialog appears above the
        # terminal/browser
        # Based on
        # http://stackoverflow.com/questions/3375227/how-to-give-tkinter-file-dialog-focus

        # Make a top-level instance and hide since it is ugly and big.
        root = tk.Tk()
        root.withdraw()

        # Make it almost invisible - no decorations, 0 size, top left corner.
        root.overrideredirect(True)
        root.geometry('0x0+0+0')

        # Show window again and lift it to top so it can get focus,
        # otherwise dialogs will end up behind the terminal.
        root.deiconify()
        root.lift()
        root.focus_force()

        return root, askopenfilename, asksaveasfilename
download.py 文件源码 项目:chat 作者: Decalogue 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def match(*, label="NluCell", topic=""):
    """Match subgraph and download.
    """
    database = Database(password="train")
    if topic:
        cypher_info = "MATCH (n:{label}) WHERE n.topic='{topic}' RETURN n"
    else:
        cypher_info = "MATCH (n:{label}) RETURN n"
    filename = asksaveasfilename(filetypes=[('QA?excel??', '*.xls')])
    keys = ['name', 'content', 'topic', 'tag', 'keywords', 'api', 'behavior', 'url', \
    "hot", 'txt', 'img', 'chart', 'parameter']
    # keys = database.graph.find_one(label).keys()
    items = database.graph.run(cypher_info.format(label=label, topic=topic)).data()
    sheets = [{"name": label, "keys": keys, "items": items}]
    write_excel(filename=filename, sheets=sheets)
ankimaker.py 文件源码 项目:ankimaker 作者: carllacan 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def select_file(self):
        options = {'defaultextension':'apkg',
                   'parent':self,
                   'title':'Select the Anki deck location'}
        self.filename = filedialog.asksaveasfilename(**options)
        if self.filename != '': 
            self.file_entry.delete(0, tkinter.END)
            self.file_entry.insert(0, self.filename)
gui.py 文件源码 项目:StochOPy 作者: keurfonluu 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def export_models(self):
        if self._check_run():
            filename = tkfile.asksaveasfilename(title = "Export models",
                                                filetypes = [ ("Pickle", ".pickle") ],
                                                defaultextension = ".pickle")
            if len(filename) > 0:
                with open(filename, "wb") as f:
                    pickle.dump(self.solver.models, f, protocol = pickle.HIGHEST_PROTOCOL)
gui.py 文件源码 项目:StochOPy 作者: keurfonluu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def export_fitness(self):
        if self._check_run():
            filename = tkfile.asksaveasfilename(title = "Export fitness",
                                                filetypes = [ ("Pickle", ".pickle") ],
                                                defaultextension = ".pickle")
            if len(filename) > 0:
                with open(filename, "wb") as f:
                    pickle.dump(self.solver.energy, f, protocol = pickle.HIGHEST_PROTOCOL)
Chapter6-2.py 文件源码 项目:Tkinter-By-Example 作者: Dvlv 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def file_new(self, event=None):
        file_name = filedialog.asksaveasfilename()
        if file_name:
            self.open_file = file_name
            self.main_text.delete(1.0, tk.END)
            self.title(" - ".join([self.WINDOW_TITLE, self.open_file]))
Chapter6-2.py 文件源码 项目:Tkinter-By-Example 作者: Dvlv 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def file_save(self, event=None):
        if not self.open_file:
            new_file_name = filedialog.asksaveasfilename()
            if new_file_name:
                self.open_file = new_file_name

        if self.open_file:
            new_contents = self.main_text.get(1.0, tk.END)
            with open(self.open_file, "w") as open_file:
                open_file.write(new_contents)
Chapter6-3.py 文件源码 项目:Tkinter-By-Example 作者: Dvlv 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def file_new(self, event=None):
        file_name = filedialog.asksaveasfilename()
        if file_name:
            self.open_file = file_name
            self.main_text.delete(1.0, tk.END)
            self.title(" - ".join([self.WINDOW_TITLE, self.open_file]))


问题


面经


文章

微信
公众号

扫码关注公众号