
dateformat | The date format to be returned. Check all Date formats here. |
firstweekday | 0=Monday, 1=Tuesday ... To display on Calendar |
startdate | Datetime, the date to be infocus, default is current date |
bootstyle | Style keyword, options are primary, secondary, success,info,warning,danger, light, dark |
**kwargs | Other keyword arguments. |
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from datetime import date
my_w = ttk.Window()
my_w.geometry("420x300") # width and height
dt2 = date(2023, 12, 30) # start date
de = ttk.DateEntry(dateformat='%Y-%m-%d', firstweekday=2, startdate=dt2)
de.grid(row=1, column=1, padx=10, pady=20)
my_w.mainloop()

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from datetime import date
my_w = ttk.Window()
my_w.geometry("520x320") # width and height
dt2 = date(2023, 12, 30) # for startdate
sel = ttk.StringVar()
de = ttk.DateEntry(dateformat='%Y-%m-%d', firstweekday=2, startdate=dt2)
de.grid(row=1, column=1, padx=10, pady=20)
def my_upd():
l1.configure(text=de.entry.get()) # displaying date
b1 = ttk.Button(my_w, text='Show date', command=lambda: my_upd())
b1.grid(row=1, column=2)
l1 = ttk.Label(my_w, text='Date') # to display date here
l1.grid(row=1, column=3)
my_w.mainloop()
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from datetime import datetime
class MyDateEntry(ttk.DateEntry):
# Override function
def _on_date_ask(self):
super()._on_date_ask()
# Generate the virtual event
self.event_generate("<<DateEntrySelected>>")
# Function to return the selected date
def get_date(self):
return datetime.strptime(self.entry.get(), self._dateformat)
# Create main window
window = ttk.Window(themename='darkly')
window.title('Calendar')
window.geometry('300x400')
# Label to display the selected date
label = ttk.Label(window, text='Date: ')
label.pack(pady=10)
# Function to update label when a date is selected
def update_label(event):
print(f'event: {event}')
date_object = event.widget.get_date()
print(date_object)
formatted_date = date_object.strftime("%A, %b %d")
print(formatted_date)
# Update the label with the selected date
label.configure(text=f'Date: {formatted_date}')
# Use the custom DateEntry widget
cal = MyDateEntry(window, bootstyle="primary")
cal.pack()
# Bind the event to the DateEntry
cal.bind('<<DateEntrySelected>>', update_label)
# Run the application
window.mainloop()
All ttkbootstrap styles are applied using the bootstyle parameter. We can use all the avilable styles and apply to DateEntry.
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from datetime import date
my_w = ttk.Window()
my_w.geometry("700x200") # width and height
c, r = 0, 0
for my_style in my_w.style.colors: # List of styles
de = ttk.DateEntry(bootstyle=my_style)
de.grid(row=r, column=c, padx=2, pady=20)
c = c + 1
if c == 4:
c, r = 0, 1
my_w.mainloop()
de.configure(state='readonly')
#de.configure(state='disabled')
de.configure(state='invalid')
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.
29-12-2024 | |
| I found a solution so you don't need a button! Override the class and generate the event, since it isn't generated. import ttkbootstrap as ttk from ttkbootstrap.constants import * from ttkbootstrap.widgets import DateEntry from datetime import datetime class MyDateEntry(ttk.DateEntry): # override function def _on_date_ask(self): super()._on_date_ask() # generate the virtual event self.event_generate("<<DateEntrySelected>>") # function to return the selected date def get_date(self): return datetime.strptime(self.entry.get(), self._dateformat) window = ttk.Window(themename='darkly') window.title('Calendar') window.geometry('300x400') label = ttk.Label(window, text='Date: ') label.pack(pady=10) def update_label(event): print(f'event: {event}') date_object = event.widget.get_date() print(date_object); formatted_date = date_object.strftime("%A, %b %d") print(formatted_date) #global label label.configure(text=f'Date: {formatted_date}') # use the custom DateEntry cal = MyDateEntry(window, bootstyle="primary") cal.pack() cal.bind('<<DateEntrySelected>>', update_label) # run window.mainloop() | |
02-02-2025 | |
| Thanks, Included above, thanks again. | |