def choose_path(self):
"""
Called when users press the 'Browse' button in order to choose a path on their system.
"""
current_path = self.getvalue()
new_path = None
# Lets users choose a new path.
if self.path_type == "file":
new_path = askopenfilename(title = self.askpath_title,
initialdir=os.path.dirname(current_path),
initialfile=os.path.basename(current_path), parent = get_parent_window(self), filetypes = self.file_types)
elif self.path_type == "directory":
new_path = askdirectory(title = self.askpath_title, initialdir=os.path.dirname(current_path), mustexist = True, parent = get_parent_window(self))
# Updates the text in the Entry with the new path name.
if new_path:
self.clear()
self.setvalue(new_path)
if hasattr(self.run_after_selection, "__call__"):
self.run_after_selection()
评论列表
文章目录