0

im pretty new to python and im trying a simple task in a GUI (using tkinter) to combine all textfiles in an given path into one file. The Text in the new file will just be all Textfiles combined. There is no order needed.

The number of textfiles in one given path can be different, so all text file endings should be considered/looked for.

I did create a gui with some entry field and buttons to let me pick the path via windows explorer.

Some code I got so far for a simple GUI with source path, destination path and new file name fields.

All I now need is to use that information given in the field to combine all textfiles and write the result in the new destination with the new file name. Thats where I struggle at the moment.

Code so far:

from tkinter import *
from tkinter import filedialog


def browse_button_source():
    global folder_path_source
    filename_source = filedialog.askdirectory()
    folder_path_source.set(filename_source)


def browse_button_destination():
    global folder_path_destination
    filename_destination = filedialog.askdirectory()
    folder_path_destination.set(filename_destination)


root = Tk()
folder_path_source = StringVar()
folder_path_destination = StringVar()

label_source = Label(root, text='Source path with textfiles, ending e.g. .txt:')
label_source.place(x=50, y=25)
path_field_source = Entry(root, textvariable=folder_path_source, width=60)
path_field_source.place(x=50, y=50)

button_source = Button(text="Source:", command=browse_button_source)
button_source.place(x=450, y=50, width=100)

label_destination = Label(root, text='Destination:')
label_destination.place(x=50, y=75)
path_field_destination = Entry(root, textvariable=folder_path_destination, width=60)
path_field_destination.place(x=50, y=100)
button_destination = Button(text="Destination:", command=browse_button_destination)
button_destination.place(x=450, y=100, width=100)

label_newfile = Label(root, text='New Filename:')
label_newfile.place(x=50, y=125)
new_filename = Entry(width=60)
new_filename.place(x=50, y=150)
# Here i planed to put a button which can take all the needed paths and create a merged textfile in the new path with the new name from entry.
# button_newfile = Button(text="Go:!", command=merge_wl)
# button_newfile.place(x=450, y=150, width=100)

root.resizable(False, False)
root.title('Merger')
root.geometry('600x250')

mainloop()

I hope my little vision is clear and I hope someone has an idea how to realize it.

Thanks for every help.

lilaaffe
  • 85
  • 6

0 Answers0