0

I would like to ask when I run the file in Pycharm, it able to show the calendar Show Calendar, but when I convert from py file to .exe format, it show no error but my calendar show nothing As show in here. I have pip install tkcalendar but may I know why my calendar not appear after convert into .exe format. I using python 3.8.2

Below are my code: 

def chooseStartDate():
    def print_sel():
        global startDate
        startDate = cal.selection_get()
        tk.Label(this, text=startDate).grid(row=4, column=2)
        top.destroy()
    top = tk.Toplevel(this)
    now = datetime.datetime.now()
    cal = Calendar(top, font="Arial 14", selectmode='day', year=now.year, month=now.month, day=now.day)
    cal.pack(fill="both", expand=True)
    tk.Button(top, text="ok", command=print_sel).pack()

this = tk.Tk()
tk.Label(this, text="Start Date: ").grid(row=4, column=0)
tk.Button(this, text="Choose Date", command=chooseStartDate).grid(row=4, column=1)
this.mainloop()

Thank you.

James Lee
  • 3
  • 5
  • You've provided no details on how you "converted into .exe format" - since Python is not by default compiled into a binary executable, you should provide some details on what tools you're using and how you used them, since that's likely where the problem is. – Grismar Apr 20 '20 at 00:36
  • @Grismar I am using window powershell to convert the .py file to .exe format. I have installed the tkcalendar (pip install tkcalendar) and it shown the requirement is satisfied. After that, I convert the .py file to .exe using "pyinstaller -w [filename]" and it able to build successfully. But when I execute the programs, it show everything fine but my calendar is show a blank window. – James Lee Apr 20 '20 at 00:42
  • Ok, your problem then is with the use of `pyinstaller`, which is not a standard part of Python, but a special tool used to create executables that include both Python and your script. PyInstaller is fine, but it can be tricky to ensure it includes all libraries you need in the build - start with adding `--hidden-import tkinter`, but there's likely to be more issues. Look at the `pyinstaller` documentation for some more hints and ideas. – Grismar Apr 20 '20 at 00:50
  • Does this answer your question? [How to install python application with tkcalendar module by pyinstaller?](https://stackoverflow.com/questions/57811928/how-to-install-python-application-with-tkcalendar-module-by-pyinstaller) – j_4321 Apr 27 '20 at 12:48

1 Answers1

1

Please use --hiddenimport=babel.numbers while generating the exe file.

This should resolve the issue.

pyinstaller.exe --onefile -w --hiddenimport=babel.numbers your_script_name.py
Paul Roub
  • 36,322
  • 27
  • 84
  • 93