Reputation: 83
I am making an app in Python 3 (for Windows) for creating some docx files, using data from csv's, using tkinter of course for GUI. The files are saved on C:\Folder1\Folder2 Is there a way to insert a link (to a specific folder) in a message box? I mean something like a box with a message: "You can find the file here" and when the user clicks on 'here', destination folder will be opened by Windows Explorer. Or, as an alternative, the docx file itself will be opened by MS Word!
Upvotes: 1
Views: 5154
Reputation: 3116
You can try following this process:
from tkinter import *
import os
root = Tk()
# path = 'C:\Folder Name'
path = 'C:\Folder Name\File Name.docx'
def open():
os.startfile(path, 'open')
button = Button(root, text="Open File Direction or File", command=open)
button.pack()
root.mainloop()
Or this:
from tkinter import *
import os
def open():
os.system("start C:/")
root = Tk()
button = Button(root, text="Open File Direction", command=open)
button.pack()
root.mainloop()
Upvotes: 2
Reputation: 2554
Windows has a command start
to do this. You can use it like this to get same behavior as when you double-click a folder/file in Windows Explorer.
Create a button to open folder and then assign command like this:
fold_btn.config(command=lambda: os.system('start "" "{}"'.format("C:\Folder1\Folder2")))
Or Create a button to open file(docx or other) and then assign command like this:
file_btn.config(command=lambda: os.system('start "" "{}"'.format("C:\Folder1\Folder2\file.docx")))
Upvotes: 1