0

What i want to do is to make 6 buttons which every single of them has a chosen (different) path.

E.g.

lbllst = []
directories = []

def choose_directory():
    #save the directory to directories list

    a = filedialog.askdirectory()   
    directories.append(a)

def open_path():
    #open the directory folder

    os.startfile(directories[0])

def add():
    choose_directory()

    if len(lbllst) < 6:
        #create and save the button in LBLLST list with specified path

        dyn_label = Button(init_tkinter,  image=img_full1, command=open_path)
        dyn_label.place(relx=0.01, rely=0.135*(len(lbllst)+1))
        lbllst.append(dyn_label)
    else:
        pass

I think the solution is obvious, but i haven't have the luck to find it yet.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Sukin Syn
  • 11
  • 4
  • It's not clear what you want. `open_path` should *probably* take a directory as an argument, rather than accessing an element of a global list of directories, and the `command` for the `Button` instance should probably be a function that calls `open_path` with a hard-coded argument (`lambda: open_path("/foo/bar")`, for example. Perhaps `choose_directory` should *return* a directory instead of appending it to the global list.) – chepner Jul 07 '23 at 16:10

0 Answers0