2

I am using py2app to create a standalone APP from a python script however I have run into a problem which I am hoping you could help with.

The script relies heavily on tkinter, primarily the tkinter messagebox module, which is not imported with tkinter but rather has to be imported separately using:

from tkinter import messagebox

In my setup.py file that I use to create the application, I have included all the modules that are used in the python, using this code:

from setuptools import setup


APP = ['ch.py']
DATA_FILES = ['company.txt']
OPTIONS = {'argv_emulation': False, 'includes':['tkinter', 'requests', 'os'], 'iconfile': 'icon.icns'}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

However when I compile the app, everything works perfect except the tkinter messageboxes, which simply don't open. I know this is because I have not specifically imported them in the setup.py file.

Does anyone know how I can tell the setup.py file to include "from tkinter import messagebox?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Ruthus99
  • 492
  • 2
  • 10
  • 25

1 Answers1

4

Found an answer after about a day of searching, basically the problem isn't with the tkinter messagebox module. The problem was with the requests module that was used to contact the API which then returned information to be displayed in the messagebox. That is why the messagebox wasnt showing, because no request to the API was being made.

To fix this you need to add the requests module to 'packages' as well as 'includes', like follows:

OPTIONS = {'argv_emulation': False, 'includes':['datetime', 'tkinter', 'requests'], 'packages':['requests'], 'iconfile':'icon.icns'}

Hope this helps anyone in the same scenario

Ruthus99
  • 492
  • 2
  • 10
  • 25
  • May I know which version of requests and py2app you are using? I can't seem to get requests to work when the program is compiled into an app, although the app GUI launches just fine. I am using requests 2.18.4 and py2app 0.10. Thank you! – Anthony L. Dec 26 '17 at 03:44
  • @AnthonyL. I'm having the same issue also with requests, did you find a solution? – Eric Apr 29 '20 at 11:09