Python .py 文件中的 Tkinter 日历小部件导入错误

Python Tkinter calendar widget import error in .py file

我正在使用 tkcalendar 小部件在 Python 中制作日历。

这是我的代码:

import tkinter as tk
from tkinter import ttk
import tkcalendar

def print_sel():
    date = cal.selection_get()
    root.destroy()

def quit1():
    root.destroy()


root = tk.Tk()
cal = tkcalendar.Calendar(root, font="Arial 11", selectmode='day',
                            year=2016, month=1, day=1)
cal.pack()
ttk.Button(root, text="Confirm", command=print_sel).pack(side="left", fill="both", expand=True)
ttk.Button(root, text="Back", command=quit1).pack(side="left", fill="both", expand=True)
date = ''
root.mainloop()

我的问题是上面的代码在 Jupyter notebook 中 运行 时工作正常,但在转换和 运行 as .p​​y file.I 时出现此错误:

import tkcalendar
ModuleNotFoundError: No module named 'tkcalendar'

当我 pip install tkcalendar 时,我得到:

Requirement already satisfied: tkcalendar in...

Requirement already satisfied: pytz>=0a in...

Requirement already satisfied: babel in...

首先建议:您应该检查 PYTHON 安装路径的位置,然后从该目录转到 cmd -> 并键入:pip installs tkcalendar。如果安装成功,那么问题出在您的解释器选择中,您的脚本是 运行。

无论如何,根据你的问题描述,它看起来 你的解释器选择你的脚本是 运行 所以先试试这个。

谢谢..享受编码。