Skip to main content

Calendar widget for use with python tkinter

Project description

Calendar Widget for use with python tkinter











INSTALLATION

Install the calendar widget using the following commands
pip install calendar_widget

USAGE

First, Import the calendar widget along with tkinter

import tkinter
from calendar_widget import Calendar
Define the tkinter window into which the widget will be placed. EXAMPLE:
root = tkinter.Tk()
root.geometry('600x600')
The Calendar Widget can then be created as follows:
Calendar = Calendar(root)
To pass a command to the Calendar, specify the command option when it is created
Calendar = Calendar(root, command=user_command, ...)
To retrieve a selected date on the calendar, use the get_date command:
Calender.get_date()
To create a checkbox on the calendar, the command is as follows:
checkbox = Calendar.checkboxes(10, 10, 2022, status=True, ...)

#to remove a chcekbox that has already been created specify the delete option as follows:

Calendar.checkboxes(10, 10, 2022, delete=True)
To destroy the calendar widget, call the destroy method:
Calendar.destroy()

Example 1 - Basic Setup


# import tkinter and the calendar widget
import tkinter
from calendar_widget import Calendar

# define the main window into which the widget will be placed
root = tkinter.Tk()
root.geometry('600x600')  # the geometry function defines the size of the tkinter window
                          # - in this case, we are using a window that is 600px by 600px

# create the calendar widget
Calendar = Calendar(root, # specify the tkinter window into which the widget will be placed
	size = 250, # set the size of the calendar widget to 250px
	pos_x = 0, # set the x position of the calendar widget within the tkinter window
	pos_y = 0, # set the y position of the calendar widget within the tkinter window
	background = 'lightblue', # set the background of the calendar to light blue
	)

# Note: images of the type 'png', 'gif', 'ppm', and 'pgm' can be set as the background.
# However, these images will not scale with the size of the calendar.

# remember to call your mainloop function so that the tkinter window is persistent
root.mainloop()

Note: if no 'pos_x' or 'pos_y' parameters are given, the Calendar widget will default to using the standard pack function.


Example 2 - Binding a command to the calendar


# the 'Calendar_Click' function retrives the date selected on the Calendar by the user, and prints the date to the console
def Calendar_Click():
	print(Calendar.getdate())

# create the calendar widget
Calendar = Calendar(root,
	size = 250,
	pos_x = 0,
	pos_y = 0, 
	background = 'lightblue', 
	command = Calendar_Click  # link the 'Calendar_Click' function to the widget
	)

Note: Only a single command can be linked to the calendar widget.


Widget Parameters - functionality and styling

The table below specifies opitons availiable for styling and other operations associated with the calendar widget

options description
size= Sets the width of the widget in pixels. The default width is 300px.
pos_x= Sets the x coordinate position of the widget within the window. Note: In tkinter, this is always the top left corner.
pos_y= Sets the y coordinate position of the widget within the window. Note: In tkinter, this is always the top left corner.
style= Set the style="Dark" for the dark theme. If no styling is specified the Calendar will inherit its default white theme.
command= A function to be called when the widget is clicked.
background= Sets the background of the Calendar to a valid tkinter colour or image (png, gif, ppm, pgm). Example: background="blue" or background='sky.png'
img_pos_x= Set the x coordinate of the background image if specified (by default, this is the top left corner)
img_pos_y= Set the y coordinate of the background image if specified (by default, this is the top left corner)
img_anchor= Set the anchor of the background image if specified (by default, this is set to 'nw' - the top left corner)
arrow_box_border= Sets the border colour of the box containing the arrows for selecting previous and following months.
arrow_box_fill= Sets the background of the box containing the arrows for selecting previous and following months
arrow_box_width= Sets the line width of the box containing the arrows for selecting previous and following months
date_box_fill= Sets the colour inside of the boxes that make up the monthly calendar grid.
date_box_width= Sets the width of the line used to create the grid for the monthly calendar.
date_boxes_outline= Sets the colour of the box outline for the boxes that make up the monthly claendar grid.
arrow_outline= Sets the colour for the outline of the polygon (i.e - triangle) that represents the calendar arrows.
arrow_fill= Sets the colour of the calendar arrows.
arrow_thickness= Sets the thickness of the calendar arrows.
arrow_active= Sets the colour for the active highlight when the mouse hovers over the calendar arrows.
weekday_border= Sets the colour for the outline of the boxes that hold the weekday headings.
weekday_fill= Sets the colour for the background of the boxes that hold the weekday headings.
weekday_width= Sets the width of the boxes that hold the weekday headings.
weekday_font_fill= Sets the colour of the text associated with the weekday headings.
weekday_font_family= Sets the type of font used to create the weekday headings.
calendar_date_title= Sets the colour of the text associated with the calendar title (ex: Aug 2020)
date_heading_font_family= Sets the font type for the Calendar date heading.
date_text_fill= Sets the colour of the text numbers associated with the month dates.
date_text_font_family= Sets the font type used to create the month dates.
trail_box_fill= Sets the colour of the background of the date boxes that trail into the previous and following months.
trail_text_fill= Sets the colour of the text numbers associated with the trailing date boxes.
date_highlight= Sets the colour of the permanent date highlight associated with the current date retrieved from the OS.
text_highlight_fill= Sets the colour of the text associated with the permanent date highlight.
user_highlight_colour= Sets the colour of the highlight that is created when the user clicks on a month date.
user_highlight_text= Sets the colour of the text associated with the user highlight.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

calendar_widget-1.0.5.tar.gz (90.9 kB view details)

Uploaded Source

Built Distribution

calendar_widget-1.0.5-py3-none-any.whl (87.6 kB view details)

Uploaded Python 3

File details

Details for the file calendar_widget-1.0.5.tar.gz.

File metadata

  • Download URL: calendar_widget-1.0.5.tar.gz
  • Upload date:
  • Size: 90.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for calendar_widget-1.0.5.tar.gz
Algorithm Hash digest
SHA256 b789349d7819898dbbfb5309deae3b6cc7d45d7557a0900609d5bf09edf5fbcd
MD5 e95c1e7e7c017687df47957dd95b778a
BLAKE2b-256 3f9f350b1a4fb220bfef957af3792ec495e5627c6dfbf6bd3b822176b7db9309

See more details on using hashes here.

File details

Details for the file calendar_widget-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for calendar_widget-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 024942fffee5c579aad8d200c4de651272cc1cc7f3fabcbba9809deb18da6ef6
MD5 e98e8d40056eb26c7ea1d66563a4b502
BLAKE2b-256 32d5dcf2576950266ca005d611fedebff3e3120a9b78dc5a7eab3c043f3b2e8f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page