本文整理匯總了Python中tkinter.filedialog.askdirectory方法的典型用法代碼示例。如果您正苦於以下問題:Python filedialog.askdirectory方法的具體用法?Python filedialog.askdirectory怎麽用?Python filedialog.askdirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tkinter.filedialog
的用法示例。
在下文中一共展示了filedialog.askdirectory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: choose_folder
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def choose_folder(project_name):
global current_video, projectini
projectini = project_name
img_dir = filedialog.askdirectory()
os.chdir(img_dir)
dirpath = os.path.basename(os.getcwd())
current_video = dirpath
print('Current Video: ' + current_video)
global frames_in
frames_in = []
for i in os.listdir(os.curdir):
if i.__contains__(".png"):
frames_in.append(i)
reset()
frames_in = sorted(frames_in, key=lambda x: int(x.split('.')[0]))
# print(frames_in)
number_of_frames = len(frames_in)
print("Number of Frames: " + str(number_of_frames))
configure(project_name)
MainInterface()
#create_data_frame(number_of_frames)
示例2: choose_directory
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def choose_directory():
directory_root = Tk()
directory_root.withdraw()
path_work = filedialog.askdirectory()
if path_work == '':
print('你沒有選擇目錄! 請重新選:')
sleep(2)
return choose_directory()
else:
# askdirectory 獲得是 正斜杠 路徑C:/,所以下麵要把 / 換成 反斜杠\
return path_work.replace('/', sep)
# 功能:檢查 歸類根目錄 的合法性
# 參數:用戶自定義的歸類根目錄,用戶選擇整理的文件夾路徑
# 返回:歸類根目錄路徑
# 輔助:os.sep,os.system
示例3: select_destination
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def select_destination(self):
"""
Check if the destination path is in the command line arguments,
if not ask user for input using filedialog.
If the destination path in arguments does not exist create it.
:return: str. Destination folder path.
"""
if self.args.dstcwd:
destination = os.getcwd()
else:
if self.args.dest is None:
print("Choose a destination path.")
destination = os.path.normpath(askdirectory())
print(f"Destination path: {destination}")
else:
destination = self.args.dest
if not os.path.exists(destination):
os.makedirs(destination)
return destination
示例4: browse_directory
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def browse_directory(self, option):
if option == "pcap":
# Reference: http://effbot.org/tkinterbook/tkinter-dialog-windows.htm
self.pcap_file.set(fd.askopenfilename(initialdir = sys.path[0],title = "Select Packet Capture File!",filetypes = (("All","*.pcap *.pcapng"),("pcap files","*.pcap"),("pcapng files","*.pcapng"))))
self.filename = self.pcap_file.get().replace(".pcap","")
if "/" in self.filename:
self.filename = self.filename.split("/")[-1]
#,("all files","*.*")
#self.filename_field.delete(0, END)
#self.filename_field.insert(0, self.pcap_file)
print(self.filename)
print(self.pcap_file)
else:
self.destination_report.set(fd.askdirectory())
if self.destination_report.get():
if not os.access(self.destination_report.get(), os.W_OK):
mb.showerror("Error","Permission denied to create report! Run with higher privilege.")
else:
mb.showerror("Error", "Enter a output directory!")
示例5: select_folder
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def select_folder(title="Select folder", folder=".", master=None):
"""
Display a box to select a folder.
If a folder is selected the folder path is returned, otherwise `None` is returned.
:param string title:
The title to be displayed on the box. Defaults to 'Select file'.
:param string folder:
The initial folder to open. Defaults to '.'.
:param App master:
Optional guizero master which the popup will be placed over. Defaults
to `None`.
:return:
The path of folder selected or `None`.
"""
if not os.path.isdir(folder):
utils.error_format("The folder '{}' specified for select_folder does not exist.".format(folder))
folder = "."
return filedialog.askdirectory(title=title, initialdir=folder, parent=None if master is None else master.tk)
示例6: select_source
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def select_source(self):
"""
Check if the source path is in the command line arguments,
if not ask user for input using filedialog.
:return: str. Source folder path.
"""
if self.args.srccwd:
source = os.getcwd()
else:
if self.args.source is None:
print("Choose a source path.")
source = os.path.normpath(askdirectory())
print(f"Source path: {source}")
else:
source = self.args.source
return source
示例7: openfile
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def openfile(self, event):
if event.widget["text"] == "..":
intput_type = self.input_type.get()
if not intput_type:
messagebox.showerror("Error", "please select the input type first.")
return
if intput_type == "video":
self.input_filename = askopenfilenames(title='select', filetypes=[
("all video format", ".mp4"),
("all video format", ".flv"),
("all video format", ".avi"),
])
elif intput_type == "image":
self.input_filename = askopenfilenames(title='select', filetypes=[
("image", ".jpeg"),
("image", ".png"),
("image", ".jpg"),
])
self.label0_["text"] = self.input_filename
elif event.widget["text"] == "...":
self.output_dir = askdirectory(title="select")
self.label1_["text"] = self.output_dir
示例8: browse_button
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def browse_button():
# Allow user to select a directory and store it in global var
# called folder_path
global folder_path
filename = filedialog.askdirectory()
folder_path.set(filename)
print(filename)
示例9: choose_file
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def choose_file(self):
path = filedialog.askdirectory(
title="選擇下載文件夾",
)
if not path:
return
path = Path(path)
self.label_text.set(str(path))
if self._config is not None:
self._config.op_store_path(self._store_name, path)
示例10: choose_location
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def choose_location(self):
"""
Shows a popup window to select a directory to choose save the lists generated. then sends the path to
the main view.
:author: Pablo Sanz Algucil
"""
path = filedialog.askdirectory(title="Choose directory",
initialdir="/home",
mustexist=True)
self.files_location = path
self.main_view.get_notify_childs(4, self.files_location)
示例11: __select_excel_output
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def __select_excel_output(self, entry_box):
path = askdirectory()
entry_box.delete(0, len(entry_box.get()))
entry_box.insert(0, path)
return path
示例12: select_dir
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def select_dir():
global DIRS
DIRS = filedialog.askdirectory() # 獲得文件夾地址
示例13: load_folder
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def load_folder(project_name):
global current_video
img_dir = filedialog.askdirectory()
os.chdir(img_dir)
print("Working directory is %s" % os.getcwd())
dirpath = os.path.basename(os.getcwd())
current_video = dirpath
print('Current Video: ' + current_video)
## get the frames
global frames_in
frames_in = []
for i in os.listdir(os.curdir):
if i.__contains__(".png"):
frames_in.append(i)
reset()
frames_in = sorted(frames_in, key=lambda x: int(x.split('.')[0]))
# print(frames_in)
number_of_frames = len(frames_in)
print("Number of Frames: " + str(number_of_frames))
configure(project_name)
curr_target_csv= os.path.join(os.path.dirname(project_name),'csv','targets_inserted',os.path.basename(img_dir)+'.csv')
df = pd.read_csv(curr_target_csv)
df = df.fillna(0)
print(df)
MainInterface()
#create_data_frame(number_of_frames)
示例14: dec_path
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def dec_path():
path = askdirectory(title = 'Select directory with files to decrypt')
if path == None or path == '':
messagebox.showwarning('Error', 'No path selected, exiting...')
return False
path = path + '/'
return path
示例15: __init__
# 需要導入模塊: from tkinter import filedialog [as 別名]
# 或者: from tkinter.filedialog import askdirectory [as 別名]
def __init__(self, initialdir, file_type):
if file_type == 'dir':
self.choice = filedialog.askdirectory(initialdir=initialdir)