def _update(self, box):
def on_click(b):
if b.description == '..':
self.path = os.path.split(self.path)[0]
else:
self.path = os.path.join(self.path, b.description)
self._update_files()
self._update(box)
buttons = []
for f in self.dirs:
button = widgets.Button(description=f, background_color='#d0d0ff', layout=widgets.Layout(width='50%'))
button.on_click(on_click)
buttons.append(button)
for f in self.files:
button = widgets.Button(description=f, layout=widgets.Layout(width='50%'))
button.style.button_color = 'powderblue'
button.on_click(on_click)
buttons.append(button)
box.children = tuple([widgets.HTML("%s" % (self.path,))] + buttons)
# example usage:
# f = FileBrowser()
# f.widget()
# <interact with widget, select a path>
# in a separate cell:
# f.path # returns the selected path
评论列表
文章目录