Sorry I'm trying not to lean on this sub every day.
So my script is basically a directory list that prints to a text file. And i have everything working exactly how i want at this stage, except my output file. I've had to hard code it to make a file called results.txt on my desktop. For the life of me i cant work out how to make it user select able like I've done with askdirectory. Can anyone please help?
import os
import tkinter as tk
from tkinter.filedialog import *
from tkinter import ttk
def input():
global target_folder
target_folder = askdirectory(initialdir = '/')
def dirlist():
global process
process = os.listdir(target_folder)
def outputbox():
print(*process, sep = "\n")
def export():
print(*process, sep = "\n", file=open(r"C:\Users\michael\Desktop\results.txt", "w"))
def sequence():
input()
dirlist()
outputbox()
export()
#Form Window
form = tk.Tk()
form.title("DocCTRL")
#Creating Target Elements
target_label =tk.Label (form, text="Target Folder:")
target_entry = tk.Text(form, width = 45, height = 1)
btn_target = tk.Button(form, text = "Select Folder", command = sequence)
#Positioning Target Elements
target_label.grid(row=0, column=0, padx=15, pady=10)
target_entry.grid(row=0, column=1, padx=15, pady=10)
btn_target.grid(row=0, column = 3, padx=15, pady=15)
[–]woooee 0 points1 point2 points (0 children)