class ChooseDirButton(ButtonWithLabel): def __init__(self, parent, button_text): super().__init__(parent, button_text) self.label_text.set('No folder specified.') self.hover_tip = Hovertip(self.label, text=self.label_text.get()) def button_pressed(self): directory = askdirectory() if not (directory is None): self.path = os.path.normpath(directory) self.label_text.set(self.path) self.hover_tip.__setattr__('text', self.label_text.get())
class ChooseFileButton(ButtonWithLabel): def __init__(self, parent, button_text): super().__init__(parent, button_text) self.label_text.set('No file specified.') self.hover_tip = Hovertip(self.label, text=self.label_text.get()) def button_pressed(self): file = askopenfile(mode='r', filetypes=FILE_EXTENSIONS) if not (file is None): self.path = os.path.normpath(file.name) self.label_text.set(self.path) self.hover_tip.__setattr__('text', self.label_text.get())