I've looked around for a bit, but might of got off track trying to fix the issue.
Trying to scan selected folder for extensions, then populate checkboxes with found extensions for user to select what extensions to move forward with. the amount of checkboxes can change source to source, tried using the super() but don't believe to be using it right.
import os
from tkinter import *
import tkinter #as tk
from tkinter import filedialog
root = tkinter.Tk()
root.withdraw()
file_path = filedialog.askdirectory()
print(file_path)
#src_folder = "../../"
src_folder = file_path
ListFiles = os.walk(src_folder)
SplitTypes = []
for walk_output in ListFiles:
for file_name in walk_output[-1]:
SplitTypes.append(file_name.split(".")[-1])
#print(SplitTypes)
extensions = []
for i in SplitTypes:
if i not in extensions:
extensions.append(i)
extensions = str(extensions)
#print(str(extensions))
print(extensions)
class CheckBox(tkinter.Checkbutton):
boxes = [] # Storage for all buttons
def __init__(self, master, *args, **options):
super(CheckBox, self).__init__()
tkinter.Checkbutton.__init__(self, *args, options) # Subclass checkbutton to keep other methods
self.boxes.append(self)
self.var = tkinter.BooleanVar() # var used to store checkbox state (on/off)
self.text = self.cget('text') # store the text for later
self.configure(variable=self.var) # set the checkbox to use our var
a=0
while a<len(extensions):
button=CheckBox(tkinter, text=extensions[a], command=print(extensions[a])) # Replace Checkbutton
a=a+1
button.pack()
extensions_check = []
for box in CheckBox.boxes:
if box.var.get(): # Checks if the button is ticked
extensions_check.append(box.text)
print(extensions_check)
error that i am getting is
C:\Users\Python\Projects\filescanner\Scripts\python.exe C:/Users/Python/Projects/filescanner/extensionfinder.py
F:/TestFolder
['xlsx', 'txt', 'avi', 'nxt']
[
Traceback (most recent call last):
File "C:/Users/Python/Projects/filescanner/extensionfinder.py", line 45, in <module>
button=CheckBox(tkinter, text=extensions[a], command=print(extensions[a])) # Replace Checkbutton
File "C:/Users/Python/Projects/filescanner/extensionfinder.py", line 36, in __init__
tkinter.Checkbutton.__init__(self, *args, options) # Subclass checkbutton to keep other methods
File "C:\Python\Current Install\lib\tkinter\__init__.py", line 2993, in __init__
Widget.__init__(self, master, 'checkbutton', cnf, kw)
File "C:\Python\Current Install\lib\tkinter\__init__.py", line 2561, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Python\Current Install\lib\tkinter\__init__.py", line 2530, in _setup
self.tk = master.tk
AttributeError: 'dict' object has no attribute 'tk'
Process finished with exit code 1
I am new to the python world and up for any advise, thank you all in advance