【问题标题】:Why my calendar show nothing after converting py file into exe为什么我的日历在将 py 文件转换为 exe 后什么也没有显示
【发布时间】:2020-04-17 08:30:51
【问题描述】:

我想问一下,当我在 Pycharm 中运行该文件时,它能够显示日历 Show Calendar,但是当我从 py 文件转换为 .exe 格式时,它没有显示错误,但我的日历没有显示 As show in here .我有 pip install tkcalendar 但我可以知道为什么我的日历在转换为 .exe 格式后没有出现。我使用 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()

谢谢。

【问题讨论】:

  • 您没有提供有关如何“转换为 .exe 格式”的详细信息 - 由于默认情况下 Python 未编译为二进制可执行文件,因此您应该提供一些有关您正在使用的工具的详细信息以及你是如何使用它们的,因为这很可能是问题所在。
  • @Grismar 我正在使用 windows powershell 将 .py 文件转换为 .exe 格式。我已经安装了 tkcalendar (pip install tkcalendar),它显示要求已经满足。之后,我使用“pyinstaller -w [filename]”将 .py 文件转换为 .exe,它能够成功构建。但是当我执行程序时,它显示一切正常,但我的日历显示一个空白窗口。
  • 好的,那么你的问题在于pyinstaller 的使用,它不是 Python 的标准部分,而是用于创建包含 Python 和脚本的可执行文件的特殊工具。 PyInstaller 很好,但要确保它包含构建中所需的所有库可能会很棘手 - 从添加 --hidden-import tkinter 开始,但可能会有更多问题。查看pyinstaller 文档以获取更多提示和想法。

标签: python python-3.x tkinter tk tkcalendar


【解决方案1】:

生成exe文件时请使用--hiddenimport=babel.numbers

这应该可以解决问题。

pyinstaller.exe --onefile -w --hiddenimport=babel.numbers your_script_name.py

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 2016-12-19
    • 2022-08-17
    相关资源
    最近更新 更多