本文整理汇总了Python中tkinter.filedialog.askopenfile方法的典型用法代码示例。如果您正苦于以下问题:Python filedialog.askopenfile方法的具体用法?Python filedialog.askopenfile怎么用?Python filedialog.askopenfile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.filedialog
的用法示例。
在下文中一共展示了filedialog.askopenfile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open_file
# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfile [as 别名]
def open_file():
"""
This method handles reading in Endless Sky mission files.
It creates a mission object for each mission it finds,
and then calls the parser to parse the data
"""
#TODO: Add handling for mission preamble(license text)
logging.debug("Selecting mission file...")
f = filedialog.askopenfile()
if f is None: # askopenfile() returns `None` if dialog closed with "cancel".
return
logging.debug("Opening file: %s" % f.name)
with open(f.name) as infile:
mission_lines = infile.readlines()
infile.close()
config.mission_file_items.empty()
parser = MissionFileParser(mission_lines)
parser.run()
config.active_item = config.mission_file_items.items_list[0]
config.gui.update_option_pane()
#end open_file
示例2: select_input
# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfile [as 别名]
def select_input(self) -> None:
file = askopenfile(title='Please select one (any) frame from your set of images.',
filetypes=[('Image Files', ['.jpeg', '.jpg', '.png', '.gif',
'.tiff', '.tif', '.bmp'])])
if not file:
return None
dir_ = os.path.dirname(file.name)
filetype = os.path.splitext(file.name)
self.files = [os.path.abspath(os.path.join(dir_, f))
for f in os.listdir(dir_)
if f.endswith(filetype)]
self.files.sort()
self.btn_output['state'] = 'normal'
示例3: choose_a_file
# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfile [as 别名]
def choose_a_file(self):
options = {}
options['defaultextension'] = '.jpg'
options['filetypes'] = [('JPEG', '.jpg'),
('GIF', '.gif'),
('PNG', '.png'),]
options['initialdir'] = os.path.realpath("\\")
options['initialfile'] = ''
options['parent'] = self
options['title'] = 'Choose a file'
self.chosenFile = filedialog.askopenfile(mode='r', **options)
if self.chosenFile:
self.chosenFilePath.set(self.chosenFile.name)
示例4: ask_where_are_the_status_file
# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfile [as 别名]
def ask_where_are_the_status_file():
print('Choose a status text file.')
status_file_path = filedialog.askopenfile(
initialdir=data_folder_path / 'tracking_data',
title='Choose a status text file.',
filetypes=(("text files", "*.txt"), ("all files", "*.*"))
)
if status_file_path == ():
print("Error! Choose a status.")
exit()
return status_file_path
示例5: ProcessNumbers
# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfile [as 别名]
def ProcessNumbers():
__logger.info("Processing numbers.")
print("Choose a text file containing full numbers with country code, one number per line.")
Tk().withdraw()
filename = askopenfile(
initialdir=data_folder_path,
title='Choose a text file with numbers.',
filetypes=[("text files", "*.txt")],
mode="r"
)
numbers = filename.readlines()
for i in range(len(numbers)):
number = numbers[i].strip("\n+")
numbers[i] = number
return numbers
示例6: open_file
# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfile [as 别名]
def open_file(self, event=0):
self.txt.delete("insert") # Ctrl+o causes a new line so we need to delete it
ftypes = [("greenBerry files", "*.gb"), ("All files", "*")]
file = filedialog.askopenfile(filetypes=ftypes)
if file != None:
self.file_dir = file.name
self.parent.title("greenBerry IDE" + " - " + file.name.replace("/", "\\"))
self.txt.delete("1.0", "end" + "-1c")
text = self.read_file(file.name)
self.txt.insert("end", text)
self.old_text = self.txt.get("1.0", "end" + "-1c")
self.key_pressed()
示例7: load_preset
# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfile [as 别名]
def load_preset(self):
file = askopenfile(filetypes=[("Synth presets", "*.ini")])
cf = ConfigParser()
cf.read_file(file)
file.close()
# general settings
self.samplerate_choice.set(cf["settings"]["samplerate"])
self.rendering_choice.set(cf["settings"]["rendering"])
self.a4_choice.set(cf["settings"]["a4tuning"])
self.to_speaker_lb.selection_clear(0, tk.END)
to_speaker = cf["settings"]["to_speaker"]
to_speaker = tuple(to_speaker.split(','))
for o in to_speaker:
self.to_speaker_lb.selection_set(int(o)-1)
for section in cf.sections():
if section.startswith("oscillator"):
num = int(section.split('_')[1])-1
osc = self.oscillators[num]
for name, value in cf[section].items():
getattr(osc, name).set(value)
osc.waveform_selected()
elif section.startswith("envelope"):
num = int(section.split('_')[1])-1
env = self.envelope_filter_guis[num]
for name, value in cf[section].items():
getattr(env, name).set(value)
elif section == "arpeggio":
for name, value in cf[section].items():
getattr(self.arp_filter_gui, name).set(value)
elif section == "tremolo":
for name, value in cf[section].items():
getattr(self.tremolo_filter_gui, name).set(value)
elif section == "echo":
for name, value in cf[section].items():
getattr(self.echo_filter_gui, name).set(value)
self.statusbar["text"] = "preset loaded."
示例8: _open
# 需要导入模块: from tkinter import filedialog [as 别名]
# 或者: from tkinter.filedialog import askopenfile [as 别名]
def _open(self):
""" Open a file. """
logger.debug("Popping Open browser")
return filedialog.askopenfile(**self._kwargs)