Python Forum
How to set the calendar widget to current date
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to set the calendar widget to current date
#4
I think this code is from one of your earlier post. I was wondering the same thing and it worked for me.
#! /usr/bin/env python3.8
'''Docstring'''

try:
    import tkinter as tk
    from tkinter import ttk
except ImportError:
    import Tkinter as tk
    import ttk
import datetime

today = datetime.date.today()

from tkcalendar import Calendar, DateEntry

def example1():
    def print_sel():
        print(cal.selection_get())

    top = tk.Toplevel(root)



    cal = Calendar(top,
                   font="Arial 14", selectmode='day',
                   cursor="hand1", year=today.year, month=today.month, day=today.day)
    cal.pack(fill="both", expand=True)
    ttk.Button(top, text="ok", command=print_sel).pack()

def example2():
    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)
    cal.pack(padx=10, pady=10)

root = tk.Tk()
s = ttk.Style(root)
s.theme_use('clam')

ttk.Button(root, text='Calendar', command=example1).pack(padx=10, pady=10)
ttk.Button(root, text='DateEntry', command=example2).pack(padx=10, pady=10)

root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: How to set the calendar widget to current date - by menator01 - May-11-2020, 08:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  return/capture the selected date from QDateEdit's calendar? issac_n 2 2,243 Jul-06-2020, 03:37 AM
Last Post: issac_n
  Tkinter calendar widget scratchmyhead 4 4,405 May-03-2020, 07:01 PM
Last Post: scratchmyhead
  [Tkinter] Retrieving a value from a calendar with a single click LagratteCchouette 4 9,736 Jan-26-2020, 04:36 PM
Last Post: LagratteCchouette

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020