Is there a reason why the code will raise an error when run via the command line compared to when run via IDLE's run module f5
command?
Recently I've been trying to improve the readability and robust-ness of my code. As a result I've been trying to remove all the from module import *
lines. I used to use from tkinter import *
and this line of my code worked perfectly fine:
self.path = filedialog.askdirectory()
But now I have changed from tkinter import *
to import tkinter as tk
and I have changed the code accordingly:
self.path = tk.filedialog.askdirectory()
A file called GUI.py imports this file with: from lib.filesearch import *
(the line of code I mentioned resides within the filesearch file.)
I run my code via IDLE and everything is fine. My GUI still works and the line self.path = tk.filedialog.askdirectory()
works like normal however, when I run the code through windows command line I get the error:
AttributeError: 'module' object has no attribute 'filedialog'
Here are the relevant bits from my code:
From filesearch.py
import tkinter as tk
def get_path(self):
"""Store user chosen path to search"""
self.paths = tk.filedialog.askdirectory(initialdir = FileSearch.DEFAULT)
return self.paths
From GUI.py
from lib.filesearch import *
def Browse(self):
self.BrowseB['state']='disabled'
self.p=self.CrawlObj.get_path()
self.AddText('Searching from Path: ' + str(self.p))
self.BrowseB['state']='normal'
Unlike this question I only have one version of python installed. Namely, Python34.