我正在使用 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 中运行时运行良好,但在转换并作为 .py 文件运行时。我收到此错误:
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...