j4321 / tkcalendar Goto Github PK
View Code? Open in Web Editor NEWCalendar widget for Tkinter
Home Page: https://pypi.python.org/pypi/tkcalendar
License: GNU General Public License v3.0
Calendar widget for Tkinter
Home Page: https://pypi.python.org/pypi/tkcalendar
License: GNU General Public License v3.0
In the calendar, when the currently displayed month is in the first year after the mindate, the "left month" button remains incorrectly disabled until a data which is a full year after mindate is reached.
For instance, if mindate is 28 December 2019 and the calendar shows any month of 2020 except December, the left month button remains disabled, basically preventing to go back to previous months.
The problem is due to the following code in calendar_.py (lines 1109 to 1123):
if dy == 0:
self._l_year.state(['disabled'])
if self._date.month == min_month:
self._l_month.state(['disabled'])
else:
self._l_month.state(['!disabled'])
elif dy == 1:
if self._date.month >= min_month:
self._l_year.state(['!disabled'])
self._l_month.state(['!disabled']) # -> wrong
else:
self._l_year.state(['disabled'])
else: # dy > 1
self._l_year.state(['!disabled'])
self._l_month.state(['!disabled']))
The correct code should be:
if dy == 0:
self._l_year.state(['disabled'])
if self._date.month == min_month:
self._l_month.state(['disabled'])
else:
self._l_month.state(['!disabled'])
elif dy == 1:
if self._date.month >= min_month:
self._l_year.state(['!disabled'])
else:
self._l_year.state(['disabled'])
self._l_month.state(['!disabled']) # -> correct: always enabled
else: # dy > 1
self._l_year.state(['!disabled'])
self._l_month.state(['!disabled']))
i.e. if we are in the first year after the mindate, the left month button should always be enabled.
Exactly the same problem occurs for maxdate and the right month button at line 1097: self._r_month.state(['!disabled'])
should not be inside the inner if-else block.
It would be a nice feature to be able to select a date range (i.e., a start date and a end date) using the calendar in some way.
Hi,
First time, thanks you for your code. I have a problem with the format date, because i work with Year-Month-Day and your date displayed in format Month-Day-Years. Do you have an solution for modified the format ? I search strftime or others in DateEntry but i didn't find informations.
Do you have idea for resolved my problem ?
Thanks you for your time and your help !
import pandas as pd
from tkcalendar import DateEntry
from datetime import date
def test_cal():
window = call_mise_en_forme()
window.mainloop()
class MyDateEntry(DateEntry):
def __init__(self, master=None, **kw):
DateEntry.__init__(self, master=None, **kw)
# add black border around drop-down calendar
self._top_cal.configure(bg='black', bd=1)
# add label displaying today's date below
tk.Label(self._top_cal, bg='gray90', anchor='w',
text='Today : %s' % date.today().strftime('%d-%m-%Y')).pack(fill='x')
class call_mise_en_forme(Tk):
def __init__(self):
Tk.__init__(self)
global liste_name, df,liste_old_name,liste_new_name, liste_taille, liste_police
self.geometry( "200x120" )
self.title( "Fonction de mise en forme" )
self.save_format = StringVar(value='Nom du format')
self.field_colonnes = StringVar(value='Nom colonne')
self.field_taille = StringVar(value='Taille police')
self.field_police = StringVar(value='Police caractere')
self.field_RGB = StringVar(value='(255,255,255)')
Mise_en_Forme = ('Proxima Nova', '8')
liste_old_name = []
liste_new_name = []
liste_taille = []
liste_police = []
# ---------------------------BUTTONS-----------------------------------------------
self.button = Button(self, text="Enregistrer la mise en forme",command=self.test)
self.button.pack(side=BOTTOM,fill=X, expand="yes",pady=4,padx =10)
self.de = MyDateEntry(self, year=2019,day=19, month=12)
self.de.focus_set()
self.de.pack()
def test(self):
print(self.de.get())
a = (self.de.get()).replace("/", "-")
print(a)
def reverse(string):
string = string[::-1]
return string
test_cal()
date_pattern format command does not change the printed output of selection_get(). it always prints in this order; yyyy-mm-dd
try:
import tkinter as tk
from tkinter import ttk
except ImportError:
import Tkinter as tk
import ttk
from tkcalendar import Calendar
def getdate():
def print_sel():
print(cal.selection_get())
top.destroy()
top = tk.Toplevel(root)
cal = Calendar(top,
font="Arial 14", selectmode='day',
cursor="hand1", firstweekday= 'sunday', date_pattern= 'm/d/yyyy')
cal.pack(fill="both", expand=True)
ttk.Button(top, text="ok", command=print_sel).pack()
root = tk.Tk()
s = ttk.Style(root)
s.theme_use('clam')
ttk.Button(root, text='Calendar', command=getdate).pack(padx=10, pady=10)
root.mainloop()
when you choose firstweekday='sunday' ,
the selected day is wrong - its showing the day before .
@VShkaberda The issue is not directly related to tkcalendar, it comes from the fact that Pyinstaller does not detect second level imports. There is a solution to fix it by giving explicit import instructions to Pyinstaller. Since not everybody using tkcalendar uses Pyinstaller I won't add unnecessary imports into tkcalendar's code.
Originally posted by @j4321 in #40 (comment)
I am having this same problem and the posted fix is not working.
pyinstaller --hidden-import babel.numbers main.py
This does not fix the problem. I don't know what has changed, but it is no-longer possible to workaround this.
Python 3.8.5
pip 21.2.4 from p:\documents\depot\autosuspendprocess\venv\lib\site-packages\pip (python 3.8)
tkcalendar 1.6.1
pyinstaller 4.5.1
Error message:
(venv) P:\Documents\Depot\autosuspendprocess>dist\main\main
Traceback (most recent call last):
File "main.py", line 1, in
import View
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "View.py", line 3, in
from tkcalendar import DateEntry
ModuleNotFoundError: No module named 'tkcalendar'
[11492] Failed to execute script 'main' due to unhandled exception!
The installation instructions state:
$ sudo apt-get install python(3)-tkcalendar
However python-tkcalendar
appears to have been deleted? If so can it be reactivated? I plan to remain on Ubuntu 16.04 LTS until it hits EOL and pulling from your repository is preferred. Otherwise I'd have to create a Frankenstein setup.
BTW I know I can change all my python program stubs from the default 2.7.12
to point to Python 3.5
. I'm just not ready to do this yet. Besides when I do finally upgrade OS to Ubuntu 20.04, Ubuntu 21.04 or another distro, Python 4 may be the standard at that time. I'm reluctant to upgrade existing Python code twice in a narrow time-frame.
Even if you simply restored the last version of python-tkcalendar
, with a notice that it is no longer being maintained, that would be terrific too.
Thanks.
Add the possibility to hide week numbers.
Prior to switching Python/Tk/Tcl versions, I had no issues with the dropdown working properly. Now, on Python 3.9.0 and Tk/Tcl 8.6, whenever I use the calendar dropdown in my GUI, I notice that an extra blank window opens outside of the main window. It doesn't have the normal structure, it is only a blank space, with no window buttons or text or color.
hi,
with a dateentry in my code, the application sometimes freezes and it is only possible to "unfreeze" it by pressing any key. I use 'Alt' key for instance because it does nothing and allows me to display the widgets.
with a Ctrl+c in the terminal that launches the application, one can see that the code is actually stuck in an update_idletasks() function of dateentry.py
$ python main.py
^CTraceback (most recent call last):
File "main.py", line 127, in <module>
MyAppName(root)
File "main.py", line 43, in __init__
self.create_widgets()
File "main.py", line 63, in create_widgets
self.tv_usage.create_treeview_interne()
File "/path/to/myappname/gui/view_interne.py", line 44, in create_treeview_interne
self.p.e_interne_date = DateEntry(fr_interne_head, selectmode='day', width=18)
File "/path/to/.virtualenvs/myappname/lib/python3.8/site-packages/tkcalendar/dateentry.py", line 138, in __init__
self._setup_style()
File "/path/to/.virtualenvs/myappname/lib/python3.8/site-packages/tkcalendar/dateentry.py", line 187, in _setup_style
self.update_idletasks()
File "/usr/lib/python3.8/tkinter/__init__.py", line 1311, in update_idletasks
self.tk.call('update', 'idletasks')
KeyboardInterrupt
I use python 3.8.0 and tkcalendar 1.6.1 on an ubuntu system
Hello!
Superb package, thank you so much for making it. I've been testing in Python 3.8 and found a bug when following your example code:
import tkinter as tk
from tkinter import ttk
from tkcalendar import DateEntry
def example3():
top = tk.Toplevel(root)
ttk.Label(top, text="Choose date").pack(padx=10, pady=10)
cal = DateEntry(
top,
width=12,
background="darkblue",
foreground="white",
borderwidth=2,
year=2010,
)
cal.pack(padx=10, pady=10)
root = tk.Tk()
ttk.Button(root, text="DateEntry", command=example3).pack(padx=10, pady=10)
root.mainloop()
The error is as follows:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\jose\AppData\Local\Programs\Python\Python38-32\Lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\jose\AppData\Local\Programs\Python\Python38-32\Lib\tkinter\__init__.py", line 804, in callit
func(*args)
File "C:\Users\jose\.virtualenvs\code-9xLWUBmM\lib\site-packages\tkcalendar\dateentry.py", line 202, in _on_theme_change
self._setup_style()
File "C:\Users\jose\.virtualenvs\code-9xLWUBmM\lib\site-packages\tkcalendar\dateentry.py", line 160, in _setup_style
self.style.map('DateEntry', **maps)
File "C:\Users\jose\AppData\Local\Programs\Python\Python38-32\Lib\tkinter\ttk.py", line 403, in map
self.tk.call(self._name, "map", style, *_format_mapdict(kw)),
_tkinter.TclError: Invalid state name r
After a lot of debugging, I figured out the reason for this.
The problem starts at dateentry.py:160
as per the stacktrace:
maps = self.style.map('TCombobox')
if maps:
self.style.map('DateEntry', **maps)
Line 160 is the third line ^
This goes on to call an internal ttk
function, which then has multiple other internal calls.
One of the internal calls is to _format_mapdict
, and receives the keyword arguments passed to self.style.map
:
...
self.tk.call(self._name, "map", style, *_format_mapdict(kw)),
...
Allegedly that function takes a mapdict and formats it to pass it off to tk.call
. This is that function's documentation:
"""Formats mapdict to pass it to tk.call.
E.g. (script=False):
{'expand': [('active', 'selected', 'grey'), ('focus', [1, 2, 3, 4])]}
returns:
('-expand', '{active selected} grey focus {1, 2, 3, 4}')"""
However, my debugging suggests that in Python3.8, it's actually returning this: ('-expand', '{ a c t i v e s e l e c t e d } g r e y f o c u s { 1 , 2 , 3 , 4 } ')
This causes big problems, naturally.
The solution seems to be to not pass keyword arguments individually, but to pass the dictionary of keyword arguments itself. Then the _format_mapdict
function will work properly:
maps = self.style.map('TCombobox')
if maps:
self.style.map('DateEntry', maps)
I can make a PR for this if you agree with this analysis.
from tkinter import Tk
from tkcalendar import Calendar
root = Tk()
Calendar(root, showweknumbers=False).pack()
week numbers are still displayed.
Hi,
since the update to Python 3.6.5 I get the following error message when the DateEntry widget is/should be created:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "ghv.py", line 434, in new_booking
self.begin_date = DateEntry(self.new_frame, locale = "de_DE", background='darkblue', foreground='white', borderwidth=2)
File "/usr/lib/python3.6/site-packages/tkcalendar.py", line 785, in __init__
self._setup_style()
File "/usr/lib/python3.6/site-packages/tkcalendar.py", line 838, in _setup_style
self.after_cancel(self._determine_bbox_after_id)
File "/usr/lib/python3.6/tkinter/__init__.py", line 769, in after_cancel
raise ValueError('id must be a valid identifier returned from '
ValueError: id must be a valid identifier returned from after or after_idle
If I try to close any open window of the application (window is not closed but all widgets disappear):
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "/usr/lib/python3.6/tkinter/__init__.py", line 2301, in destroy
for c in list(self.children.values()): c.destroy()
File "/usr/lib/python3.6/tkinter/__init__.py", line 2301, in destroy
for c in list(self.children.values()): c.destroy()
File "/usr/lib/python3.6/site-packages/tkcalendar.py", line 947, in destroy
self.after_cancel(self._determine_bbox_after_id)
File "/usr/lib/python3.6/tkinter/__init__.py", line 769, in after_cancel
raise ValueError('id must be a valid identifier returned from '
ValueError: id must be a valid identifier returned from after or after_idle
I can reproduce this behaviour with the example code given on this website (the Calendar widget still works).
As I am not familiar with the machanics of tcl/tk/tkinter I have no clue what is going on.
tcl 8.6.8
tk 8.6.8
Python 3.6.5
tkcalendar 1.2.0 (installed with pip 10)
Clicking on the DateEntry widget's drop-down menu will not produce the drop-down calendar on Mac OSX using the default aqua theme. There is no error message, but nothing happens. Reading the changelog, it looks like this was previously an issue on Windows but has been fixed. However, it is still not working on Mac. Using the "clam" theme does work, however.
In Windows, when clicking on the downarrow button of a DateEntry
using ttk default syle for Windows, the drop-down calendar does not show up. On the contrary, every thing works fine with 'clam' theme.
It most likely comes from the fact that some themes are more configurable than others and for those one the custom style for the DateEntry
does not work properly.
DateEntry
is expected to work: alt, clamtkcalendar/tkcalendar/dateentry.py
Line 313 in 0c6aa7c
creating a subclass of DateEntry causes this error:
class cDateEntry(DateEntry):
def __init__(self, master, **kwargs):
kw_wid, kw_pak = pack_opts(**kwargs) # splits widget keywords from pack keywords for single line creation.
if 'date_pattern' not in kw_wid.keys():
kw_wid['date_pattern'] = "dd/mm/yyyy" #default to uk format
DateEntry.__init__(*(self, master), **kw_wid)
if len(kw_pak) != 0:
self.pack(kw_pak)
def insert(self, data): #auto converts datetime to string format
try:
if isinstance(data, datetime.datetime) or isinstance(data, datetime.date):
super().insert(data.strftime("%d/%m/%Y"))
else:
super().insert(data)
except:
super().insert(data)
Simply chaning self.insert(0, txt)
to super().insert(0, txt)
fixes this issue. I would recommend the same for self.delete(0, 'end')
to `super().delete(0, 'end')
Any chance support could be added for the dateEntry widget when choosing a ttk theme. Seems ok on most but the "black" option has an error. When the date is picked the entry appear blank until highlighted. OS is Windows 10 python 3
Hi,
When I put the cursor over an event in the calendar, I see no hovering message, nothing seems to happen. I have tested using the code in the example you have supplied, and that doesn't work.
Windows 10, Python 3.7.4 and tkcalendar 1.4.
I can't find any other reports on this, so am I doing something wrong?
Thank you
after generating the .exe by using pyinstaller im facing "no module named tkcalendar" some times and some times "no module named babel.numbers" .kindly help me to get out from this issue
If year 1993-02-28 was selected in the DateEntry for example, the get_date() method returns 2093-02-28. If I use the get() method it returns correct date as string but I won't be able to know for example if 3/6/93 means 03-06-1993 or 03-06-2093. Please do help.
Thanks.
I've created a tkinter GUI, the main window contains a Calendar, and one of the register Top Level window contains the Date Entry. The bug occurs when i open my register window with the Date Entry(I don't need to do nothing on the window, just open). After this, when i try to change the month on the main window, i get a locale error and the Calendar doesn't work anymore. I've tried to find the bug by myself, but i wasn't able to. Some things i think it's important to say: If i don't change the locale to pt_BR, that is my language, doesn't happen the error, but the language of the month of the calendar change after i open the register window. I'll attach my project files here, maybe it helps. Here is the code from the Main window: https://pastebin.com/58v6UWP3 and here from the register window: https://pastebin.com/qYHdJPU7
The error that shows on the prompt is this:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Guilherme Afonso\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\Guilherme Afonso\AppData\Local\Programs\Python\Python36\lib\site-packages\tkcalendar.py", line 600, in _next_month
self._display_calendar()
File "C:\Users\Guilherme Afonso\AppData\Local\Programs\Python\Python36\lib\site-packages\tkcalendar.py", line 518, in _display_calendar
header = self._cal.formatmonthname(year, month, 0, False)
File "C:\Users\Guilherme Afonso\AppData\Local\Programs\Python\Python36\lib\calendar.py", line 529, in formatmonthname
return s.center(width)
File "C:\Users\Guilherme Afonso\AppData\Local\Programs\Python\Python36\lib\calendar.py", line 498, in __exit__
_locale.setlocale(_locale.LC_TIME, self.oldlocale)
File "C:\Users\Guilherme Afonso\AppData\Local\Programs\Python\Python36\lib\locale.py", line 598, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
Running Python 3.7.3 on macOS (installed with Homebrew), the DateEntry widget doesn't appear when the arrow is clicked. Dates can still be manually entered in the field as if it were an Entry field. This occurs in code as simple as is found below:
import tkinter as tk
import tkinter.ttk as ttk
import tkcalendar as tkc
def main():
root = tk.Tk()
test_frame = ttk.Frame(root)
test_frame.pack(side='top', fill='both', expand=True)
test_date_entry = tkc.DateEntry(test_frame)
test_date_entry.pack()
root.mainloop()
if __name__ == '__main__':
main()
I saw the same issue already posted on "Problem with ttk.Treeview and calendar #9" but now I am using Python 3.6 on windows 10 and having the same issue. When use "pip install tkcalendar" it says all requirements satisfied. So it seems like updating tkCalendar will not help :(. Any advice please?
import tkinter as tk
import tkinter.ttk as ttk
import tkcalendar as tkc
def main():
root = tk.Tk()
test_frame = ttk.Frame(root)
test_frame.pack(side='top', fill='both', expand=True)
test_date_entry = tkc.DateEntry(test_frame)
test_date_entry.pack()
root.mainloop()
if __name__ == '__main__':
main()
I try your example code above and when I click the drop-down-arrow nothing happens except I get the error message below.
The text filed of DateEntry shows the date in ISO-format 2019-07-19
Python 3.7.4, tkinter 8.6, Windows 10.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\Magnus\AppData\Roaming\Python\Python37\site-packages\tkcalendar\dateentry.py", line 207, in _on_b1_press
self.drop_down()
File "C:\Users\Magnus\AppData\Roaming\Python\Python37\site-packages\tkcalendar\dateentry.py", line 278, in drop_down
date = self.parse_date(self.get())
File "C:\Users\Magnus\AppData\Roaming\Python\Python37\site-packages\tkcalendar\calendar_.py", line 927, in parse_date
return parse_date(date, self._properties['locale'])
File "C:\Users\Magnus\AppData\Roaming\Python\Python37\site-packages\babel\dates.py", line 1168, in parse_date
return date(year, month, day)
ValueError: day is out of range for month
Originally posted by @magnuskson in #41 (comment)
I use Windows10 with Python 3.6.5
and tkcalendar 1.2.1
when I use DateEntry() and click on dropdown button
it nothing happen and got this error
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python36-64\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:\Python36-64\lib\site-packages\tkcalendar.py", line 895, in _on_b1_press
self.drop_down()
File "C:\Python36-64\lib\site-packages\tkcalendar.py", line 967, in drop_down
self._validate_date()
File "C:\Python36-64\lib\site-packages\tkcalendar.py", line 926, in _validate_date
self._date = self._calendar.strptime(self.get(), '%x').date()
File "C:\Python36-64\lib\_strptime.py", line 565, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "C:\Python36-64\lib\_strptime.py", line 345, in _strptime
format_regex = _TimeRE_cache.compile(format)
File "C:\Python36-64\lib\_strptime.py", line 275, in compile
return re_compile(self.pattern(format), IGNORECASE)
File "C:\Python36-64\lib\re.py", line 233, in compile
return _compile(pattern, flags)
File "C:\Python36-64\lib\re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Python36-64\lib\sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "C:\Python36-64\lib\sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "C:\Python36-64\lib\sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "C:\Python36-64\lib\sre_parse.py", line 759, in _parse
raise source.error(err.msg, len(name) + 1) from None
sre_constants.error: redefinition of group name 'w' as group 4; was group 3 at position 87
what I have to do?
Thank you.
I'm not sure where the problem is, but since pyinstaller works with basically every other module I'm using, I'm going to guess that this one is calling something in a way it doesn't like.
Currently this works great when ran as a python file, but when made into a .exe with pyinstaller, it fails to load past the tkcalendar calls.
build data seems to show a inability to find particular modules:
missing module named tkFont - imported by tkcalendar.calendar_ (optional)
missing module named ttk - imported by tkcalendar.dateentry (optional), tkcalendar.calendar_ (optional), tkcalendar.tooltip (optional)
Just putting this out there to see if anyone else has encountered this.
I am trying to run the example code given on the main page and I am getting the following import error:
ImportError: cannot import name 'Calendar' from partially initialized module 'tkcalendar' (most likely due to a circular import) (C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\__init__.py)
Full stack trace:
Traceback (most recent call last):
File "calendar.py", line 9, in <module>
from tkcalendar import Calendar, DateEntry
File "C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\__init__.py", line 26, in <module>
from tkcalendar.dateentry import DateEntry
File "C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\dateentry.py", line 35, in <module>
from tkcalendar.calendar_ import Calendar
File "C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\calendar_.py", line 27, in <module>
import calendar
File "C:\Users\Dan\Desktop\True Gravity Baseball\calendar.py", line 9, in <module>
from tkcalendar import Calendar, DateEntry
ImportError: cannot import name 'Calendar' from partially initialized module 'tkcalendar' (most likely due to a circular import) (C:\Users\Dan\AppData\Local\Programs\Python\Python38\lib\site-packages\tkcalendar\__init__.py)
I've tried a number of potential solutions and nothing seems to work.
Any ideas on how to resolve this would be greatly appreciated. Thanks! :)
When determining your calendar cursor, for example, cursor = 'hand1', the cursor of the opened calendar does not change.
The problem was fixed as follows:
class DateEntry(ttk.Entry):
...
def __init__(self, master=None, **kw):
...
for key in self.entry_kw:
if not key in ['cursor']:
entry_kw[key] = kw.pop(key, self.entry_kw[key])
...
If I place a DateEntry on a frame my application begins to behave poorly and have high CPU.
If I comment out: self.bind('<<ThemeChanged>>', lambda e: self.after(10, self._on_theme_change))
in the __init__
for DateEntry then things seem to work fine.
The frame is a tab in a ttk Notebook.
import datetime
today = datetime.date.today()
mindate = today - datetime.timedelta(days=5*365) # 2014-08-14
maxdate = today - datetime.timedelta(days=3*356) # 2016-09-09
calVar = StringVar()
calVar.set('13.08.2019')
cal = DateEntry(top, width=12, textvariable=calVar,
borderwidth=2, selectmode='day', locale='ru_RU',
mindate=mindate, maxdate=maxdate,
)
The date specified through textvariable is older than maxdate. When the calendar opens up, the date is automatically set to maxdate. But, this date is marked as disabled on the calendar (white foreground font color and white background).
You can fix it in "calendar_.py":
def _display_calendar(self):
...
if maxdate is not None:
mi, mj = self._get_day_coords(maxdate)
if mi is not None:
for j in range(**mj+1**, 7): # for j in range(mj, 7):
...
Hello, I tried to use mindate and maxdate to limit the range of dates which can be selected. However, the options also disable valid ranges. For example,
dt_min = date(2012, 1, 10)
dt_max = date(2014, 12, 30)
wStart = tkcalendar.DateEntry(menuFrame, date_pattern='d/mm/y',
mindate=dt_min, maxdate=dt_max)
won't let me select a date in January 2014:
Edit: In calendar_.py, on line 957, I changed
if y1 == y2 or (y1 - y2 == 1 and m1 == 1 and m2 == 12) or (y2 - y1 == 1 and m2 == 1 and m1 == 12):
to
if (y1 == y2 and m1 == m2) or (y1 - y2 == 1 and m1 == 1 and m2 == 12) or (y2 - y1 == 1 and m2 == 1 and m1 == 12):
Now it seems to work fine in my case, please check if this is correct.
Hi j4321,
First bravo for this nice piece of code !
I've been looking for a way to display events to the your calendar. For example birthdays or holidays, colorize them or write notes in the calendar, but I can't seem to find how to do that.
I'm wondering if you're already working on something alike?
To be sure, I'm new to github and coding so maybe there is a another way to ask you that then "opening a ticket" :)
Anyway have a good day
Bastien
Add possibility to choose first week day.
platform windows 10 Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32
tkcalendar 1.6.1
My program is
import tkinter
import datetime
import tkcalendar
def changement_date(event, l_date):
date_choisie = event.widget.get_date()
date_python = datetime.datetime.strptime(date_choisie,"%d/%m/%Y")
if date_python not in l_date[0]:
evt_id = event.widget.calevent_create(date_python, "")
l_date[0].append(date_python)
l_date[1].append(evt_id)
print(l_date)
else:
pos = l_date[0].index(date_python)
id = l_date[1][pos]
l_date[0].remove(date_python)
l_date[1].remove(id)
event.widget.calevent_remove(id)
print(l_date)
if __name__ == '__main__':
fen_principale = tkinter.Tk(className="Usage tkcalendar")
liste_dates_id = [[],[]]
calendrier = tkcalendar.Calendar(fen_principale,
width=12,
background='darkblue',
foreground='white',
borderwidth=2,
year=2022,
locale='fr_FR')
calendrier.bind("<<CalendarSelected>>",
lambda event: changement_date(event, liste_dates_id))
calendrier.pack()
fen_principale.mainloop()
for date_selec in liste_dates_id :
print(date_selec)
I run programm and I select three date in calendar :
Now I click in mer 9 blue vanish (that's ok)
but I have got an exception in console
[[datetime.datetime(2022, 2, 8, 0, 0)], [0]]
[[datetime.datetime(2022, 2, 8, 0, 0), datetime.datetime(2022, 2, 9, 0, 0)], [0, 1]]
[[datetime.datetime(2022, 2, 8, 0, 0), datetime.datetime(2022, 2, 9, 0, 0), datetime.datetime(2022, 2, 10, 0, 0)], [0, 1, 2]]
[[datetime.datetime(2022, 2, 8, 0, 0), datetime.datetime(2022, 2, 10, 0, 0)], [0, 2]]
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\tkinter\__init__.py", line 814, in callit
func(*args)
File "C:\Users\Laurent\AppData\Roaming\Python\Python39\site-packages\tkcalendar\tooltip.py", line 221, in display_tooltip
self.tooltip['text'] = self.widgets[str(self.current_widget)]
KeyError: '.!calendar.!frame2.!label20'
What's wrong in my program?
The date validation manually entered in Dateentry works a little strange. Any characters entered on the left or right of the day, month, year, the program considers valid. For example, if you set the date 12.03.2010 in the calendar, and then enter fg15jkl.iu08.2019jhe in the Entry field, the calendar opens on the date 15.08.2019. Validation only works if the characters are entered inside the day, month, year, for example, 1gh6.08.2019.
Calendar v1.5, OS Windows, 'locale': 'ru_RU'
Bug appears after updating from version 1.5.0
to 1.5.1
. After using resizable
method of tkinter.Tk
with parameters True
main window behaviour changes to always on top.
Reproducable example based on example3
from readme. Bug appears after clicking on DateEntry
:
from tkcalendar import Calendar, DateEntry
import tkinter as tk
from tkinter import ttk
def example3():
top = tk.Toplevel(root)
ttk.Label(top, text='Choose date').pack(padx=10, pady=10)
cal = DateEntry(top, width=12, background='darkblue',
foreground='white', borderwidth=2, year=2010)
cal.pack(padx=10, pady=10)
root.resizable(width=True, height=True) # bug cause
root = tk.Tk()
ttk.Button(root, text='DateEntry', command=example3).pack(padx=10, pady=10)
root.mainloop()
tkcalendar.zip
I hacked tkcalendar.py to support the textvariable option to get it's initial value and to set it when the day is clicked. Also added get_date() and set_date() methods to use when reading/writing config files. I also needed to have multiple calendars up on the same frame.
Hi,
First thank you for sharing your code.
tkcalendar works very well on its own but I have encountered an issue when using it with ttk.Treeview widget. Hope you can point me in the wright direction on what is causing window to expand by its self when adding DateEntry widget. Any help would be much appreciated.
Iโm using Python 2.7.
Here is short version of my code to clarify error:
from Tkinter import *
import tkMessageBox
import ttk
from tkcalendar import DateEntry
naslovi = ("Rd_br", "Naziv_usluge")
proz = Tk()
proz_baze = Frame(proz, bg = "red")
proz_baze.pack(fill="both", expand=True)
proz_baze_gumb = Frame(proz, bg = "green")
proz_baze_gumb.pack(fill="both", expand=False)
tabli = ttk.Treeview(proz_baze, columns=naslovi, show="headings")
tabli.heading("Rd_br", text="Rd br:")
tabli.column("Rd_br", width=40)
tabli.heading("Naziv_usluge", text="Naziv usluge:")
tabli.column("Naziv_usluge", width=720 / 5 - 10)
tabli.grid(column=0, row=0, in_=proz_baze, pady=5, padx=5)
napomenaPonuda = Label(proz_baze_gumb, text="Ponuda vrijedi do:")
napomenaPonuda.grid(row=1, sticky=W)
proz_baze_gumb.grab_set()
napomenaPonudaUnos = DateEntry(proz_baze_gumb, background='darkblue', foreground='white', borderwidth=2)
napomenaPonudaUnos.grid(row=1, column=1)
proz.mainloop()
It is not clear why the initial date is automatically set when the Dateentry calendar is initialized. Date selection is expected from the user, but not from the program. If you use the 'textvariable' parameter when creating the calendar, the Entry field remains empty during initialization, but when the calendar opens up, the current date is automatically substituted again.
Calendar v1.5, OS Windows 10.
I suggest that calendar numbers that do not fall into the mindate-maxdate range should not be highlighted with the cursor specified through the cursor="..." parameter.
Here are the calendar_.pu code snippets to implement this:
class Calendar(ttk.Frame):
def __init__(self, master=None, **kw):
...
# curs = kw.pop("cursor", "")
self.curs = kw.pop("cursor", "hand2")
ttk.Frame.__init__(self, master, class_=classname, name=name)
...
self._properties = {"cursor": self.curs,
...
self._l_month = ttk.Button(f_month,
style='L.%s.TButton' % self._style_prefixe, cursor=self.curs,
command=self._prev_month)
self._r_month = ttk.Button(f_month,
style='R.%s.TButton' % self._style_prefixe, cursor=self.curs,
command=self._next_month)
self._l_year = ttk.Button(f_year, style='L.%s.TButton' % self._style_prefixe, cursor=self.curs,
command=self._prev_year)
self._r_year = ttk.Button(f_year, style='R.%s.TButton' % self._style_prefixe, cursor=self.curs,
command=self._next_year)
def _display_calendar(self):
...
if maxdate is not None:
mi, mj = self._get_day_coords(maxdate)
if mi is not None:
# for j in range(mj, 7):
for j in range(mj + 1, 7):
self._calendar[mi][j].state(['disabled'])
self._calendar[mi][j].config(cursor='')
for i in range(mi + 1, 6):
for j in range(7):
self._calendar[i][j].state(['disabled'])
self._calendar[i][j].config(cursor='')
if mindate is not None:
mi, mj = self._get_day_coords(mindate)
if mi is not None:
for j in range(mj):
self._calendar[mi][j].state(['disabled'])
self._calendar[mi][j].config(cursor='')
for i in range(mi):
for j in range(7):
self._calendar[i][j].state(['disabled'])
self._calendar[i][j].config(cursor='')
def _display_days_with_othermonthdays(self):
...
label.configure(text=txt, style=style, cursor=self.curs)
Is there a way to highlight specific dates?
So I have notice people already touching on this subject. Happily I followed the instructions by them but I seem to get nowhere in my position,
from tkinter import *
import sqlite3
from tkcalendar import *
import datetime
import babel.numbers
I added the babel.numbers
import from what I read in other post.
import calendar
from babel.dates import format_date, parse_date, get_day_names, get_month_names
from babel.numbers import *
I also added the last two line to my calendar.py
and I even added --hidden-import babel.numbers
while running pyinstaller but I still can run my .exe file because tkcalendar not found.
hiddenimports=['babel.numbers'],
Please Help
Drop down displays 2/29/2000. This day didn't exist.
Pressing the Combobox list button again when the calendar is open does not hide it, but reopens it.
Solution to the problem in "tkcalendar.py":
def _on_focus_out_cal(self, event):
if self.focus_get() is not None:
...
else:
if 'active' in self.state(): # if xc <= x <= xc + w and yc <= y <= yc + h:
self._calendar.focus_force()
else:
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.