I have a GUI where I ask the user to select the directory and create a folder. Then it has the user browse for a file. That file is then read and directed to an absolute file path. I would, instead, like that path to be the user selected path and folder and cannot figure that out! Please help. _/_
from tkinter import *
from tkinter import ttk, filedialog
from tkinter.filedialog import askopenfile
import os
import pandas as pd
def selectPath():
path_ = askdirectory()
path.set(path_)
def create_subfolder():
print("folder_name: ", folder.get())
print("path_name: ", path.get())
dirs = os.path.join(path.get(), folder.get())
if not os.path.exists(dirs):
os.makedirs(dirs)
tkinter.messagebox.showinfo('Tips:','Folder name created successfully!')
else:
tkinter.messagebox.showerror('Tips','The folder name exists, please change it')
path = tk.StringVar() # Receiving user's file_path selection
folder = tk.StringVar() # Receiving user's folder_name selection
tk.Entry(window,textvariable = path).place(relx=0.05, rely=0.12, relheight=0.06, relwidth=0.30)
tk.Button(window, text = "Select your directory: ", command = selectPath).place(relx=0.37, rely=0.11, relheight=0.08, relwidth=0.30)
tk.Entry(window,textvariable = folder).place(relx=0.05, rely=0.20, relheight=0.06, relwidth=0.30)
tk.Button(window, text = "Submit Folder Name: ", command = create_subfolder).place(relx=0.37, rely=0.19, relheight=0.08, relwidth=0.30)
def openFile():
filename = filedialog.askopenfilename(initialdir = r'C:\ABC\123\MyFile',
filetypes=[("Excel Files", "*.xlsx")])
os.startfile(filename)
df = pd.read_excel(filename, sheet_name = 'Order Details')
df.to_excel(r'C:\ABC\123\MyFile_2.xlsx')
can this be df.to_excel(dirs)?
def onClick():
tk.messagebox.showinfo("Importing My File", "Your file imported!")
button = tk.Button(canvas, text='Import Intelliscan File', bg='LightYellow2', fg='black',command=openFile)
button.place(relx=0.05, rely=0.29, relheight=0.13, relwidth=0.30)
window.mainloop()```
Thanks in advance!