Skip to Content
Menu
This question has been flagged
2253 Views

I am using pamdas to generate excel reports,  I want a way to download files in the location that user select.

i.e when a user click the button a "select file dialog" popup to the user.


I Used the following code :


import tkinter
from tkinter import filedialog
import os

root = tkinter.Tk()
root.withdraw()
# use to hide tkinter window


def search_for_file_path(self):
currdir = os.getcwd()
tempdir = filedialog.askdirectory(parent=root, initialdir=currdir, title='Please select a directory')
if len(tempdir) > 0:
print("You chose: %s" % tempdir)
return tempdir

out_path = self.search_for_file_path()


but the following Error Come :

tempdir = filedialog.askdirectory(parent=root, initialdir=currdir, title='Please select a directory') File "C:\Python36-32\Lib\tkinter\filedialog.py", line 428, in askdirectory return Directory(**options).show() File "C:\Python36-32\Lib\tkinter\commondialog.py", line 39, in show w = Frame(self.master) File "C:\Python36-32\Lib\tkinter\__init__.py", line 2738, in __init__ Widget.__init__(self, master, 'frame', cnf, {}, extra) File "C:\Python36-32\Lib\tkinter\__init__.py", line 2293, in __init__ (widgetName, self._w) + extra + self._options(cnf)) RuntimeError: main thread is not in main loop


Any Help

Avatar
Discard