A simple Monthly Calendar Display

Ene Uran 0 Tallied Votes 285 Views Share

Nothing fancy. just shows a simple monthly calendar in a Tkinter label. The trick is to use a fixed font so spaces take up the same area as numbers.

# as simple monthly calendar with Tkinter
# tested with Python25   EU    02/02/2007

import calendar as cd
import Tkinter as tk

# supply year and month
year = 2007
month = 2    # jan=1

# assign the month's calendar to a multiline string
str1 = cd.month(year, month)

# create the window form and call it root (typical)
root = tk.Tk()
root.title("Monthly Calendar")

# pick a fixed font like courier so spaces behave right 
label1 = tk.Label(root, text=str1, font=('courier', 14, 'bold'), bg='yellow')
label1.pack(padx=3, pady=5)

# run the event loop (needed)
root.mainloop()
Ene Uran 638 Posting Virtuoso

Please add justify='left' to the tk.Label arguments. The default text alignment is 'center' and that screws things up. My bad!

ndhdo 0 Newbie Poster

the last week somehow display incorrectly for 10/2008

ndhdo 0 Newbie Poster

My bad that did not read author comment :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.