0

I have a Python 3.3 script which uses tkinter and tkinter.filedialog. The latter is being used in this particular line of one of the classes:

self.root_folder = os.path.realpath(tk.filedialog.askdirectory(**self.dir_opt))

The code runs well in IDLE. However, after being converted to a binary executable using py2exe, the program runs, but raises the following exception when trying to call the named line:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
    return self.func(*args)
  File "analyzer.py", line 403, in load_files
  File "analyzer.py", line 388, in select_root
AttributeError: 'module' object has no attribute 'filedialog'

The setup.py:

from distutils.core import setup
import py2exe

setup()
setup(
    console=['analyzer.py'],
    options={
        'py2exe': 
        {'includes': ['lxml.etree', 'lxml._elementpath', 'tkinter', 'tkinter.filedialog'],
         }
    }
)

I checked the contents of tkinter.__dict__ in the IDLE and binary versions. The executable lacks indeed the filedialog attribute, among some others. For instance:

**IDLE**          **EXE**
_varnum           _varnum
colorchooser        
commondialog      
constants         constants
dialog            
filedialog        
font              
getboolean        getboolean
getdouble         getdouble
getint            getint
image_names       image_names 
image_types       image_types
mainloop          mainloop
messagebox        
re                re

What am I doing wrong? I would be really grateful for your help.

PS. The very same problem seems to appear also when trying cx_Freeze.

1 Answer 1

1

You have to import from tkinter import filedialog I have no idea why, but if you just from tkinter import * or import tkinter it won't work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.