0

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()
2
Contributors
3
Replies
7
Views
10 Years
Discussion Span
Last Post by ndhdo
0

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

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.