1
from tkinter import *
from tkcalendar import *

def get_date():
    calendar.configure(today.get_date())


win = Tk()
win.title('Calendar Picker')

labeltext = StringVar()
label = Label(win,textvariable=labeltext)
label.pack(pady=10)

btn = Button(win,text='Pick a date',command=get_date)
btn.pack(pady=10)

today = Calendar(win,selectmode='day',year=2020,month=8,day=6)

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    from tkcalendar import Calendar
  File "C:\Python38\lib\site-packages\tkcalendar\__init__.py", line 26, in <module>
    from tkcalendar.dateentry import DateEntry
  File "C:\Python38\lib\site-packages\tkcalendar\dateentry.py", line 35, in <module>
    from tkcalendar.calendar_ import Calendar
  File "C:\Python38\lib\site-packages\tkcalendar\calendar_.py", line 27, in <module>
    import calendar
  File "E:/Python/Python Projects Fun\calendar.py", line 18, in <module>
    today = Calendar(win,selectmode='day',year=2020,month=8,day=6)
NameError: name 'Calendar' is not defined

I already pip installed tkcalendar however if I use the Calendar widget it showed the NameError. May I ask what's the requirement if I use Calendar for tkcalendar module? Is there something that I not yet installed? Anyone know how to solve the above problem? Because I checked the module tkcalendar includes Calendar widget. After I recognize the name crashes this problem, after I understand the mistake and change it then next time I will know how to deal with it.

1 Answers1

4

Your script is named calendar.py which crashes the Python built-in module calendar which is used by tkcalendar.

Rename your script to other name.

acw1668
  • 40,144
  • 5
  • 22
  • 34
  • I see in your other question [cant-load-calendar-with-corresponding-date](https://stackoverflow.com/questions/63276211/cant-load-calendar-with-corresponding-date) that you have renamed the script. If it solved this question, please accept it as an answer. – acw1668 Aug 06 '20 at 04:41